gpt4 book ai didi

php - 我不能做外键,约束错误

转载 作者:可可西里 更新时间:2023-11-01 07:34:23 25 4
gpt4 key购买 nike

我有一个通信错误,我无法解决它,已知为 [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 *slug column*来自 slugs table .

最佳答案

我猜 string 数据类型不能是 unsigned(),这就是您收到错误的原因。

在两个迁移中使用它:

$table->string('slug')->nullable();

关于php - 我不能做外键,约束错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37208144/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com