【发布时间】:2014-03-30 20:49:50
【问题描述】:
我使用外键“user_id”迁移到另一个数据库中的表“用户”: 当我输入(php artisan migrate)时,这会产生错误。
[Illuminate\Database\QueryException]
SQLSTATE[42000]: Syntax error or access violation: 1072 Key column 'user_id
' doesn't exist in table (SQL: alter table `safetyreports` add constraint s
afetyreports_user_id_foreign foreign key (`user_id`) references `users` (`i
d`) on delete cascade)
现在 laravel 制作了除了 'user_id' 列之外的表格。 laravel 为什么不做专栏?
这是我的迁移代码:
Schema::create('safetyreports', function(Blueprint $table) {
$table->increments('id');
$table->string('afdeling');
$table->string('contractor');
$table->string('directe chef');
$table->string('ploeg');
$table->string('team');
$table->string('plant_afd');
$table->string('datum');
$table->string('plaats');
$table->string('tijd');
$table->string('omschrijving');
$table->foreign('user_id')
->references('id')->on('users')
->onDelete('cascade');
$table->timestamps();
});
This is a the important part of my Users model code:
protected $connection = 'mysql2';
protected $table = 'users';
I have tested my Users model. It works. I perform (cross-database) user authentication with this model.
【问题讨论】:
标签: database laravel-4 foreign-keys eloquent