SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint

Posted 1 year ago by venkat1806

I know there are many threads related to this error. I have gone through most of them but still i could not resolve it

two files

2017_09_06_123917_create_posts_table.php

       Schema::create('posts', function (Blueprint $table) {
            $table->increments('id');
        $table->integer('sr')->nullable();

2017_09_06_123926_create_updates_table.php

        Schema::create('updates', function (Blueprint $table) {
            $table->increments('id');
        $table->unsignedInteger('sr_id')->nullable();
        $table->text('update');
            $table->timestamps();
        });
    Schema::table('updates', function ($table) {
        $table->foreign('sr_id')->references('sr')->on('posts')->onDelete('cascade');
        });

$table->engine=InnoDB; in config/database.php under mysql

Please help fixing the error.

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.