Laravel schema builder INT (11) for integer () and INT (10) for unsignedInteger ()
Why does Laravel create an integer column as INT (11) and an unsigned integer column as INT (10)?
$table->integer('integer'); // INT(11)
$table->unsignedInteger('unsignedInteger'); // INT(10) unsigned
$table->integer('integer_then_unsigned')->unsigned(); // INT(10) unsigned
Since the maximum unsigned number can be almost twice as large, shouldn't it be the other way around?
+3
source to share
3 answers
I have the same problem and I tried to add unsigned to id, but it didn’t help, but it still had int (10), this is a structure created by maggots migration:
CREATE TABLE `products` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
`created_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
CREATE TABLE `product_user` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`product_id` int(11) NOT NULL,
`user_id` int(11) NOT NULL,
`created_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY (`id`),
UNIQUE KEY `product_user_unique` (`product_id`,`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
if you try to add outer constraints it will return an error:
alter table `product_user add constraint user_foreign
foreign key (`user_id`) references `users` (`id`) on delete cascade;
eneral error: 1215 Unable to add foreign key constraint
My workaround is to remove unsigned from product_id, user_id
-1
source to share