Reputation: 593
I need to create two tables:
First articles
:
public function up()
{
Schema::create('articles', function (Blueprint $table) {
$table->increments('id');
$table->integer('user_id')->unsigned();
$table->string('title');
$table->text('body');
$table->timestamps();
$table->timestamp('roba_spremna');
$table->timestamp('auction_end');
$table->string('key');
$table->foreign('user_id')
->references('id')
->on('users')
->onDelete('cascade');
});
}
and then offers
:
public function up()
{
Schema::create('offers', function (Blueprint $table) {
$table->increments('id');
$table->integer('user_id')->unsigned();
$table->integer('article_id');
$table->integer('price');
$table->string('comment');
$table->timestamps();
$table->foreign('user_id')
->references('id')
->on('users')
->onDelete('cascade');
$table->foreign('article_id')
->references('id')
->on('articles')
->onDelete('cascade');
});
}
When I run php artisan migrate
I get:
What is the problem? Why I cant create succesfully this two tables?
Upvotes: 1
Views: 686
Reputation: 1223
If you want to reference id
column of a table your column needs to be unsigned, the article_id
column in offers
table is not unsigned , make it unsigned and refresh the migration
Upvotes: 1
Reputation: 17701
It's because table is already created. Delete table and re run.
Upvotes: 1