Laravel-5-Generators-Extended icon indicating copy to clipboard operation
Laravel-5-Generators-Extended copied to clipboard

Fails to migrate Foreign Constraints

Open k3rne1pan1c opened this issue 1 year ago • 0 comments

  • Laravel Version: 10.X.X
  • PHP Version: ^8.1
  • Laravel-5-Generators-Extended Version: 2.0.2
  • Command: sail artisan migrate

What I did

I have the generated users table of Backpack, so there is an ID given. I used the example in the Laravel-5-Generators-Extended README so my expectation is that this should work.

sail artisan make:migration:schema create_users_profile  --schema="user_id:unsignedInteger:foreign, display_name:string, username:string, avatar:string, age:integer, height:integer, origin: string, hair_color: string, location: string, radius:string, orientation: string, availability:string, description: text"

This generated the following:

...
    public function up()
    {
        Schema::create('users_profile', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->unsignedInteger('user_id');
            $table->foreign('user_id')->references('id')->on('users');
          ...
        });
    }
...

What I expected to happen

Migrate should work and tables plus table relationship should be created.

What happened

 SQLSTATE[HY000]: General error: 3780 Referencing column 'user_id' and referenced column 'id' in foreign key constraint 'users_profile_user_id_foreign' are incompatible. (Connection: mysql, SQL: alter table `users_profile` add constraint `users_profile_user_id_foreign` foreign key (`user_id`) references `users` (`id`))

What I've already tried to fix it

??

k3rne1pan1c avatar Dec 15 '23 19:12 k3rne1pan1c