Laravel 8 迁移展示 "SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax"
Laravel 8 migration show "SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax"
当 运行 "php artisan migrate:fresh" 命令显示 SQLSTATE[42000] 错误
这是完整的错误信息
SQLSTATE[42000]:语法错误或访问冲突:1064 您的 SQL 语法有误;查看与您的 MySQL 服务器版本相对应的手册,了解在第 1 行 'unsigned not null, created_at
timestamp null, updated_at
timestamp null) def' 附近使用的正确语法 (SQL: create table products
(id
bigint unsigned not null auto_increment 主键,name
varchar(191) not null,description
varchar(1000) not null,quantity
int unsigned not null,status
varchar(191) not null default 'unavailable', image
varchar(191) not null default 'unavailable', seller_id
varchar(191) unsigned not null, created_at
timestamp null, updated_at
timestamp null) default character set utf8mb4 collate 'utf8mb4_unicode_ci')
这是迁移
Product::UNAVAILABLE_PRODUCT 在产品模型中定义为 'unavailabel'
public function up()
{
Schema::create('products', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('description',1000);
$table->integer('quantity')->unsigned();
$table->string('status',)->default(Product::UNAVAILABLE_PRODUCT);
$table->string('image',)->default(Product::UNAVAILABLE_PRODUCT);
$table->string('seller_id',)->unsigned();
$table->timestamps();
$table->foreign('seller_id')->references('id')->on('users');
});
}
$table->string('seller_id',)->unsigned();
没有无符号字符串这样的东西。删除此列的 unsigned()
选项,或者将其定义为整数。
当 运行 "php artisan migrate:fresh" 命令显示 SQLSTATE[42000] 错误
这是完整的错误信息
SQLSTATE[42000]:语法错误或访问冲突:1064 您的 SQL 语法有误;查看与您的 MySQL 服务器版本相对应的手册,了解在第 1 行 'unsigned not null, created_at
timestamp null, updated_at
timestamp null) def' 附近使用的正确语法 (SQL: create table products
(id
bigint unsigned not null auto_increment 主键,name
varchar(191) not null,description
varchar(1000) not null,quantity
int unsigned not null,status
varchar(191) not null default 'unavailable', image
varchar(191) not null default 'unavailable', seller_id
varchar(191) unsigned not null, created_at
timestamp null, updated_at
timestamp null) default character set utf8mb4 collate 'utf8mb4_unicode_ci')
这是迁移 Product::UNAVAILABLE_PRODUCT 在产品模型中定义为 'unavailabel'
public function up()
{
Schema::create('products', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('description',1000);
$table->integer('quantity')->unsigned();
$table->string('status',)->default(Product::UNAVAILABLE_PRODUCT);
$table->string('image',)->default(Product::UNAVAILABLE_PRODUCT);
$table->string('seller_id',)->unsigned();
$table->timestamps();
$table->foreign('seller_id')->references('id')->on('users');
});
}
$table->string('seller_id',)->unsigned();
没有无符号字符串这样的东西。删除此列的 unsigned()
选项,或者将其定义为整数。