Error in Ravel 7 migration General error: 3780

Asked 2 years ago, Updated 2 years ago, 400 views

Ravel 7

I would like to migrate, but I get the following error:This error usually results in solutions from $table->bigInteger('user_id')->unsigned(); or $table->unsignedBigInteger().
There were other unresolvable errors, so I deleted the database and tried phpartisan migrate several times, but I got the following error:

SQLSTATE [HY000]: General error: 3780 Referencing column 'user_id' and referenced column 'id' in foreign key constraint 'user_group_user_id_foreign' are incompatible. (SQL:alterable `user_group `addressed_signore_group)

  at vendor/larvel/framework/src/Illuminate/Database/Connection.php:671
    667 | // If an exception occurred when attempting to run a query, we'll format the error
    668 | // message to include the bindings with SQL, which will make this exception a
    669 | // lot more helpful to the developer installed of just the database's errors.
    670 | catch(Exception$e){
  >671 | through new QueryException (
    672 | $query, $this-> prepareBindings($bindings), $e
    673|             );
    674|         }
    675|

      +9 vendor frames
  10database/migrations/2020_06_11_152935_create_user_groups_table.php:19
      Illuminate\Support\Facades\Facade::__callStatic("create")

      +22 vendor frames
  33 artisan—37
      Illuminate\Foundation\Console\Kernel::handle (Object(Symphony\Component\Console\Input\ArgvInput), Object(Symphony\Component\Console\Output\ConsoleOutput))

The purpose was to create a chat app, and the table configuration was as follows, and the intermediate table and groups, comments were php make:migration.Users are tables created by phpartisan uvue --auth.

users<-->Intermediate table (user_groups)<-->groups
           ↑
           ↓
         comments

↓ is database/migrations/2020_06_11_152935_create_user_groups_table.php.

use Illuminate\Database\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateUserGroupsTable extensions Migration
{
    public function up()
    {
        Schema::create('user_groups', function(Blueprint$table){
            $table->increments('id');
            $table->bigInteger('user_id')->unsigned();
            $table->bigInteger('group_id')->unsigned();
            $table->foreign('user_id')->references('id')->on('users');
            $table->foreign('group_id')->references('id')->on('groups');
            $table->unique(['user_id', 'group_id', 'uq_user_groups');
            $table->timestamps();
        });
    }

    public function down()
    {
        Schema::dropIfExists('user_groups');
    }
}

Thank you for your cooperation.

laravel

2022-09-30 21:50

1 Answers

I had set the target id of the foreign key with increments('id') so all I had to do was $table->integer('user_id')->unsigned(); in create_user_groups_table.php.


2022-09-30 21:50

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.