亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

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

SQLSTATE[42000]:語法錯誤或訪問沖突:1072 表中不存在鍵列“proform_id”

SQLSTATE[42000]:語法錯誤或訪問沖突:1072 表中不存在鍵列“proform_id”

PHP
浮云間 2023-10-15 16:45:49
php artisan migrate:fresh 之后出現錯誤:SQLSTATE[42000]:語法錯誤或訪問沖突:1072 表中不存在鍵列“proform_id”(SQL:alter tableproforms添加約束proforms_proform_id_foreign外鍵(proform_id)引用proforms(id)刪除級聯)這是生成錯誤的遷移:2020_08_08_093303_create_dynamic_field.php<?phpuse Illuminate\Support\Facades\Schema;use Illuminate\Database\Schema\Blueprint;use Illuminate\Database\Migrations\Migration;class CreateDynamicField extends Migration{    /**     * Run the migrations.     *     * @return void     */    public function up()    {        Schema::create('dynamic_fields', function (Blueprint $table) {            $table->increments('id');            $table->string('id_pozycji')->nullable();            $table->string('name')->nullable();            $table->string('PKWIU')->nullable();            $table->integer('quantity')->nullable();            $table->integer('unit')->nullable();            $table->integer('netunit')->nullable();            $table->integer('nettotal')->nullable();            $table->integer('VATrate')->nullable();            $table->integer('grossunit')->nullable();            $table->integer('grosstotal')->nullable();            $table->integer('proform_id')->nullable();            $table->timestamps();            $table->time('deleted_at')->nullable();        });        Schema::table('proforms', function (Blueprint $table){            $table->foreign('proform_id')                  ->references('id')                  ->on('proforms')                  ->onDelete('cascade');                    });    }    /**     * Reverse the migrations.     *     * @return void     */    public function down()    {        Schema::dropIfExists('dynamic_fields');    }}
查看完整描述

2 回答

?
白豬掌柜的

TA貢獻1893條經驗 獲得超10個贊

這對我來說看起來很奇怪:


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

    $table->foreign('proform_id')

          ->references('id')

          ->on('proforms')

          ->onDelete('cascade');            

});

看起來您正在嘗試添加一個外鍵并引用它自己的表。


proform_id桌子上沒有proforms。該語句需要在表上運行dynamic_fields。


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

    $table->foreign('proform_id')

          ->references('id')

          ->on('proforms')

          ->onDelete('cascade');            

});


查看完整回答
反對 回復 2023-10-15
?
開滿天機

TA貢獻1786條經驗 獲得超13個贊

嘗試添加foreignId而不是像這樣只添加foreignId:


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

        $table->foreignId('user_id')

              ->references('id')

              ->on('users')

              ->onDelete('cascade');


查看完整回答
反對 回復 2023-10-15
  • 2 回答
  • 0 關注
  • 191 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號