我有一个commum错误,我不能去了吧,知道作为[Illuminate\Database\QueryException] SQLSTATE[42000]
这里是完整的错误:我不能做一个外键约束错误
[Illuminate\Database\QueryException] SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'unsigned null' at line 1 (SQL: alter table
files
addslug
varchar(255) unsigned null)
分离的错误:
[PDOException] SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'unsigned null' at line 1
他是我想要做的外键的表:
文件
public function up()
{
Schema::create('files', function($table)
{
$table->engine = 'InnoDB';
$table->increments('id')->unsigned();
$table->string('name')->nullable();
$table->boolean('enable_sch')->nullable();
$table->datetime('schdate')->nullable();
$table->string('flsize')->nullable();
$table->timestamps();
});
Schema::table('files', function($table)
{
$table->string('slug')->unsigned()->nullable();
$table->foreign('slug')->references('slug')->on('slugs');
});
}
蛞蝓
public function up()
{
Schema::create('slugs', function($table)
{
$table->engine = 'InnoDB';
$table->string('nameslug');
$table->string('slug')->unsigned()->nullable();
$table->timestamps();
});
}
public function down()
{
Schema::dropIfExists('slugs');
}
我试图做的是从slugs table
添加到files table
的*slug column*
。
请避免链接唯一的答案,但引用为您的解决方案的相关部分。 – k0pernikus