【发布时间】:2020-04-01 16:51:46
【问题描述】:
列存在但迁移时返回
SQLSTATE[42000]:语法错误或访问冲突:1072 表中不存在键列
当我删除外键时,问题就解决了
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
}
public function up()
{
Schema::create('skills', function (Blueprint $table) {
$table->increments('id');
$table->string('skill_name')->nullable();
$table->decimal('skill_note')->nullable();
$table->timestamps();
});
}
public function up()
{
Schema::create('skill_user', function (Blueprint $table) {
$table->increments('id');
$table->unsignedInteger('user_id');
$table->foreign('user_id ')
->references('id')->on('users');
$table->unsignedInteger('skill_id');
$table->foreign('skill_id')
->references('id')->on('skills');
$table->decimal('note')->nullable();
$table->timestamps();
});
}
【问题讨论】:
-
显示您对
skills和users的迁移 -
哪个版本的 Laravel?
-
@aynber 完成请帮忙:(
-
@kerbholz 版本 6
-
如果您在上次迁移后对技能或用户表进行了任何修改,您必须运行命令
php artisan migrate:fresh。因为在我看来,您提供的代码应该一切顺利。还要确保您的skill_user迁移在其他表之后运行。
标签: php laravel eloquent migration