lundi 24 mars 2014

Foreign Key issue with Laravel migration


Vote count:

0




I've been looking around on here for the answer but nothing seems to work. I've done a base install of Laravel and Sentry 2. Firstly i've added this migration to add a client_id column to the users table.



Schema::table('users', function(Blueprint $table)
{
$table->integer('client_id')->unique;
});


Then next i created my clients table with the following in a different migration.



Schema::create('clients', function(Blueprint $table)
{
$table->increments('id');
$table->timestamps();
$table->integer('client_id')->unique;
$table->string('client_name');
$table->date('expiry');
$table->integer('cals');
});


Finally i created a migration with the following in.



$table->foreign('client_id')
->references('client_id')->on('clients')
->onDelete('cascade');


The error im getting is the following;



SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint (SQL: alter table `users` add constraint use
rs_client_id_foreign foreign key (`client_id`) references `clients` (`client_id`) on delete cascade)


I'm a little stuck on what i should be looking for, should they both be indexes?



asked 34 secs ago

Nathan

581





Aucun commentaire:

Enregistrer un commentaire