francois
123
18
General

Migrations change() failure

Posted 3 years ago by francois

Hello,

On an existing table, I'd like to add foreign key. So, I've created a migration file :

Schema::table('addresses', function(Blueprint $table)
        {
            $table->foreign('id_user')->references('id')->on('users')->unsigned()->change();
            $table->foreign('id_country')->references('id')->on('regions')->unsigned()->change();

        });

But, when I run php artisan migrate, I have this error :

 [Illuminate\Database\QueryException]                                                                                                                                                                      
  SQLSTATE[HY000]: General error: 1005 Can't create table 'homestead.#sql-445_25' (errno: 150) (SQL: alter table `ps_addresses` add constraint addresses_id_user_foreign foreign key (`id_user`) reference  
  s `ps_users` (`id`))                                                                                                                                                                                      
                                                                                                
  [PDOException]                                                                                
  SQLSTATE[HY000]: General error: 1005 Can't create table 'homestead.#sql-445_25' (errno: 150)

My composer.json file include doctrine/dbal so I really don't understand.

Thanks

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

Reply to

Use Markdown with GitHub-flavored code blocks.