![](/img/trans.png)
[英]SQL error: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax
[英]SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; Error making a migration table
我正在嘗試使用 php、laravel、mysql 和 css 制作網上商店。 但是當我嘗試使用產品和訂單的外鍵制作遷移表時,我收到此錯誤:
SQLSTATE[42000]:語法錯誤或訪問沖突:1064 你的 SQL 語法有錯誤; 檢查手冊對應到你的MariaDB的服務器版本正確的語法使用近
'unsigned not null, `description` text unsigned not null, `price` decimal(8, 2...'
在1號線(SQL:create table `orders` (`id` int unsigned not null auto_increment primary key, `user_id` int unsigned not null, `product_id` int unsigned not null, `name` varchar(255) unsigned not null, `description` text unsigned not null, `price` decimal(8, 2) unsigned not null, `totalAmount` decimal(8, 2) null, `created_at` timestamp null, `updated_at` timestamp null) default character set utf8mb4 collate 'utf8mb4_unicode_ci'
)
這是我的遷移表此時的樣子:
Schema::create('orders', function (Blueprint $table) {
$table->increments('id')->primary()->unsigned();
$table->integer('user_id');
$table->integer('product_id');
$table->string('name');
$table->text('description');
$table->decimal('price');
$table->decimal('totalAmount');
$table->timestamps();
$table->foreign('user_id')->references('id')->on('users');
$table->foreign('product_id')->references('id')->on('products');
});
誰能幫我解決這個問題?
在有問題的查詢文本中,我們看到:
...
`name` varchar(255) unsigned not null,
`description` text unsigned not null,
...
但是字符串類型的列不能有UNSIGNED
屬性。 這是一個錯誤。
我不知道為什么會在您的情況下發生這種情況以及如何治愈這種情況。
代替 :
$table->increments('id')->primary()->unsigned();
你可以簡單地這樣做:
$table->id();
(至少對於 Laravel 7+)
php工匠遷移:回滾
或者
php工匠遷移
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.