微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

SQLSTATE [42000]:语法错误或访问冲突:1072表中不存在键列'proform_id'

如何解决SQLSTATE [42000]:语法错误或访问冲突:1072表中不存在键列'proform_id'

PHP artisan迁移之后:我收到错误消息:

sqlSTATE [42000]:语法错误或访问冲突:1072表中不存在键列'proform_id'(sql:alter table proforms添加约束proforms_proform_id_foreign外键({{1} })在删除级联上引用proform_idproforms

这是迁移,会产生错误: 2020_08_08_093303_create_dynamic_field.PHP

id

这是与之相关的迁移: 2020_07_29_101958_proforms.PHP

<?PHP

use 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');
    }
}

解决方法

这对我来说很奇怪:

Prop({ ... })

您似乎正在尝试添加引用自己表的外键。

Schema::table('proforms',function (Blueprint $table) { $table->foreign('proform_id') ->references('id') ->on('proforms') ->onDelete('cascade'); }); 表上没有proform_id。该语句需要在proforms表上运行。

dynamic_fields

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。