lundi 26 novembre 2018

Migration problem. "Foreign key constraint is incorrectly formed". Laravel

Here are my tables:

Users table

public function up()
{
    Schema::create('users', function (Blueprint $table) {
        $table->increments('id');
        $table->string('username')->unique();
        $table->string('password');
        $table->integer('subscriber_id')->unsigned(); 
        $table->rememberToken();
        $table->timestamps();

        $table->foreign('subscriber_id')
            ->references('id')
            ->on('subscribers');
    });
}

Subscribers table

public function up()
{
    Schema::create('subscribers', function (Blueprint $table) {
        $table->increments('id');
        $table->string('name')->nullable();
        $table->timestamps();
    });
}

Everytime I "php artisan migrate" this message always prompts and blocks me on migrating:

Illuminate\Database\QueryException  : SQLSTATE[HY000]: General error: 1005 Can't create
 table `emade`.`#sql-de4_9e` (errno: 150 "Foreign key constraint is incorrectly formed")
 (SQL: alter table `users` add constraint `users_subscriber_id_foreign` foreign key (`subs
criber_id`) references `subscribers` (`id`))

I just confused on above lines returned:
1. can't create table 'emade' - 'emade' is not my table, it is my database
2. users_subscriber_id_foreign ??

I had burn a lot of time of this problem. I have really no idea whats happening, Sirs, please help..



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire