我不能做外键,约束错误
I can't do a foreign key, constraint error
我有一个通信错误,我无法解决它,[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
add slug
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');
}
我想要做的是将 files table
添加到 slugs table
中的 *slug column*
。
我猜 string
数据类型不能是 unsigned()
,这就是您收到错误的原因。
在两个迁移中使用它:
$table->string('slug')->nullable();
由于我将 OctoberCMS 与 Laravel 一起使用,因此 **models** file
上有 relationships
,例如 $hasMany
和 $belongsTo
。
如果在 OctoberCMS 上遇到此问题,请咨询 this
我有一个通信错误,我无法解决它,[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');
}
我想要做的是将 files table
添加到 slugs table
中的 *slug column*
。
我猜 string
数据类型不能是 unsigned()
,这就是您收到错误的原因。
在两个迁移中使用它:
$table->string('slug')->nullable();
由于我将 OctoberCMS 与 Laravel 一起使用,因此 **models** file
上有 relationships
,例如 $hasMany
和 $belongsTo
。
如果在 OctoberCMS 上遇到此问题,请咨询 this