Laravel 6 - SQLSTATE[42000]:语法错误或访问冲突:1064 您的 SQL 语法有误;
Laravel 6 - SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax;
当我运行
php artisan migrate
迁移此 Schema
public function up()
{
Schema::create('transaction_ins', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('idTransactionIN');
$table->date('buy_date');
$table->string('id_Supplier')->unsigned();
$table->string('id_DeviceType')->unsigned();
$table->string('id_DeviceBrand')->unsigned();
$table->string('device_name');
$table->mediumText('device_name');
$table->decimal('device_price', 11, 2);
$table->integer('amount');
$table->decimal('sum_price', 15, 2);
$table->mediumText('context');
$table->timestamps();
//Foreign Key
$table->foreign('id_Supplier')->references('idSupplier')->on('suppliers')->onUpdate('cascade');
$table->foreign('id_DeviceType')->references('idDeviceType')->on('device_types')->onUpdate('cascade');
$table->foreign('id_DeviceBrand')->references('idDevicebrand')->on('device_brands')->onUpdate('cascade');
});
}
我收到此错误消息
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 MariaDB server version for the
right syntax to use near 'unsigned not null, id_DeviceType
varchar(255) unsigned not null, id_DeviceBra' at line 1 (SQL: create
table
transaction_ins(
idbigint unsigned not null auto_increment
primary key,
idTransactionINvarchar(255) not null,
buy_datedate
not null,
id_Suppliervarchar(255) unsigned not null,
id_DeviceTypevarchar(255) unsigned not null,
id_DeviceBrand
varchar(255) unsigned not null,
device_namevarchar(255) not null,
device_namemediumtext not null,
device_pricedecimal(11, 2) not
null,
amountint not null,
sum_pricedecimal(15, 2) not null,
contextmediumtext not null,
created_attimestamp null,
updated_at` timestamp null) default character set utf8mb4 collate
'utf8mb4_unicode_ci')
你不能让字符串无符号,那是指整数
只需删除 unsigned 修饰符(如果它们确实是字符串)
$table->string('id_Supplier');
$table->string('id_DeviceType');
$table->string('id_DeviceBrand');
将 string 数据类型更改为 integer 数据类型,将标记为 unsigned
的数据类型
当我运行
php artisan migrate
迁移此 Schema
public function up()
{
Schema::create('transaction_ins', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('idTransactionIN');
$table->date('buy_date');
$table->string('id_Supplier')->unsigned();
$table->string('id_DeviceType')->unsigned();
$table->string('id_DeviceBrand')->unsigned();
$table->string('device_name');
$table->mediumText('device_name');
$table->decimal('device_price', 11, 2);
$table->integer('amount');
$table->decimal('sum_price', 15, 2);
$table->mediumText('context');
$table->timestamps();
//Foreign Key
$table->foreign('id_Supplier')->references('idSupplier')->on('suppliers')->onUpdate('cascade');
$table->foreign('id_DeviceType')->references('idDeviceType')->on('device_types')->onUpdate('cascade');
$table->foreign('id_DeviceBrand')->references('idDevicebrand')->on('device_brands')->onUpdate('cascade');
});
}
我收到此错误消息
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 MariaDB server version for the right syntax to use near 'unsigned not null,
id_DeviceType
varchar(255) unsigned not null,id_DeviceBra' at line 1 (SQL: create table
transaction_ins(
idbigint unsigned not null auto_increment primary key,
idTransactionINvarchar(255) not null,
buy_datedate not null,
id_Suppliervarchar(255) unsigned not null,
id_DeviceTypevarchar(255) unsigned not null,
id_DeviceBrandvarchar(255) unsigned not null,
device_namevarchar(255) not null,
device_namemediumtext not null,
device_pricedecimal(11, 2) not null,
amountint not null,
sum_pricedecimal(15, 2) not null,
contextmediumtext not null,
created_attimestamp null,
updated_at` timestamp null) default character set utf8mb4 collate 'utf8mb4_unicode_ci')
你不能让字符串无符号,那是指整数
只需删除 unsigned 修饰符(如果它们确实是字符串)
$table->string('id_Supplier');
$table->string('id_DeviceType');
$table->string('id_DeviceBrand');
将 string 数据类型更改为 integer 数据类型,将标记为 unsigned
的数据类型