Answer the question
In order to leave comments, you need to log in
SQLSTATE[42S21] Error Why are foreign keys not being set?
I form a migration to change the table
php artisan make:migration ChangeArticlesTable --table=articles
$table->integer('user_id')->unsigned()->default(1);
$table->foreign('user_id')->references('id')->on('users');
$table->integer('category_id')->unsigned()->default(1);
$table->foreign('category_id')->references('id')->on('categories');
php artisan migrate
[Illuminate\DATABASE\QueryException]
SQLSTATE[42S21]: COLUMN already EXISTS: 1060 Duplicate COLUMN name 'user_id'
(SQL: ALTER TABLE 'articles' ADD 'user_id' INT UNSIGNED NOT NULL DEFAULT ‘1’, ADD 'catego ry_id' INT UNSIGNED NOT NULL DEFAULT ’l’)
[PDOException]
SQLSTATE[42S21]: COLUMN already EXISTS: I960 Duplicate COLUMN name ’user_id'
Answer the question
In order to leave comments, you need to log in
uhmm, so what? the religion does not allow to create at once the table with keys?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question