I’m trying to make a webshop using php, laravel, mysql and css. But when i try to make a migration table using foreign keys for products and orders i get this error:
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, `description` text unsigned not null, `price` decimal(8, 2...'
at line 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'
)
This is how my migration table looks like as of this moment:
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'); });
Anyone that can help me solve this problem?
Advertisement
Answer
Instead of :
$table->increments('id')->primary()->unsigned();
you could simply do this:
$table->id();
(At least for Laravel 7+)