Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fails to migrate Foreign Constraints #203

Open
k3rne1pan1c opened this issue Dec 15, 2023 · 0 comments
Open

Fails to migrate Foreign Constraints #203

k3rne1pan1c opened this issue Dec 15, 2023 · 0 comments

Comments

@k3rne1pan1c
Copy link

  • 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

??

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant