I tried to change the forma but nothing changed. I have this migration tables and I want to link between them one to many relation , but I got an error.
this is the poster(publisher) table:
Schema::create('posters', function (Blueprint $table) {
$table->increments('id'); // tha means integer
$table->string('username');
$table->string('email');
$table->timestamps();
});
this is article table :
Schema::create('articles',function(Blueprint $table){
$table->increments('id');
$table->integer('poster_id')->unsigned(); //it s integer too
$table->string('name');
$table->longText("content");
$table->foreign('poster_id')->references('id')->on('posters')->onDelete("cascade");
});
full error :
SQLSTATE[HY000]: General error: 1005 Can't create table
laravel
.articles
(errno: 150 "Foreign key constraint is incorrectly formed") (SQL: alter tablearticles
add constraintarticles_poster_id_foreign
foreign key (poster_id
) referencesposters
(id
) on delete cascade)