第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Laravel 遷移已成功遷移,但未在表中創(chuàng)建外鍵關(guān)系

Laravel 遷移已成功遷移,但未在表中創(chuàng)建外鍵關(guān)系

PHP
動漫人物 2023-11-03 16:46:26
我的 Laravel 應(yīng)用程序成功創(chuàng)建了遷移中的所有表,但無法在表中創(chuàng)建外鍵關(guān)系,甚至在刪除主記錄時無法強(qiáng)制級聯(lián)。這是遷移。    Schema::create('articles', function (Blueprint $table) {        $table->id('id');        $table->unsignedBigInteger('user_id');        $table->string('title');        $table->text('excerpt');        $table->text('body');        $table->timestamps();        $table->foreign('user_id')            ->references('id')            ->on('users')            ->onDelete('cascade');    });當(dāng)我運行時 php artisan migrate它遷移成功。λ php artisan migrateMigration table created successfully.Migrating: 2014_10_12_000000_create_users_tableMigrated:  2014_10_12_000000_create_users_table (0.11 seconds)Migrating: 2014_10_12_100000_create_password_resets_tableMigrated:  2014_10_12_100000_create_password_resets_table (0.1 seconds)Migrating: 2019_08_19_000000_create_failed_jobs_tableMigrated:  2019_08_19_000000_create_failed_jobs_table (0.07 seconds)Migrating: 2020_08_26_122846_create_articles_tableMigrated:  2020_08_26_122846_create_articles_table (0.14 seconds)但是,當(dāng)我檢查數(shù)據(jù)庫時,沒有創(chuàng)建關(guān)系,只是創(chuàng)建外鍵索引。 檢查此鏈接中的文章表圖像。我已經(jīng)標(biāo)記了必要的部分在此處檢查用戶表圖像。我已經(jīng)突出顯示了主鍵。我添加了一些與用戶和文章相關(guān)的工廠數(shù)據(jù),當(dāng)我刪除用戶時,這些文章將被保留為孤立的??赡艹鍪裁磫栴}了?PHP 版本:7.3.21MySql版本:5.7.31MariaDB 版本:10.4.13Laravel 框架版本:7.25.0先感謝您。
查看完整描述

2 回答

?
德瑪西亞99

TA貢獻(xiàn)1770條經(jīng)驗 獲得超3個贊

我所做的就是轉(zhuǎn)到config文件夾然后database.php將 mysql 數(shù)據(jù)庫引擎從 null 更改為 innoDB 即來自:


//...

'engine' => null,

//...

到:


//...

'engine' => 'InnoDB',

//...


查看完整回答
反對 回復(fù) 2023-11-03
?
慕桂英546537

TA貢獻(xiàn)1848條經(jīng)驗 獲得超10個贊

您用于Schema::create創(chuàng)建表。


在 Laravel 文檔中,我Schema::table在使用外鍵時看到。也許你應(yīng)該嘗試拆分你的代碼:


Schema::create('articles', function (Blueprint $table) {

    $table->id('id');

    $table->unsignedBigInteger('user_id');

    $table->string('title');

    $table->text('excerpt');

    $table->text('body');

    $table->timestamps();

});


Schema::table('articles', function (Blueprint $table) {

    $table->foreign('user_id')

        ->references('id')

        ->on('users')

        ->onDelete('cascade');


});


查看完整回答
反對 回復(fù) 2023-11-03
  • 2 回答
  • 0 關(guān)注
  • 136 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號