blueprint
blueprint copied to clipboard
Generation of multiple Primary Keys / Auto Increment
- Laravel Version: 9.29.0
- PHP Version: 8.10.0
- Blueprint Version: 2.4.0
- Platform: Mac | Windows | Linux
Issue:
When using size attribute with any integer blueprint integer (bigInteger, mediumInteger, tinyInteger, smallInteger, etc...), it will generate a Laravel migration format that call SQL to create a Primary Key with Auto Increment. Please check this similar generated Issue.
draft.yaml:
code_no: smallInteger:3 unsigned unique
will generate
$table->unsignedSmallInteger('code_no', 3)->unique()
It maybe more adequate to generate
$table->unsignedSmallInteger('code_no')->length(3)->unique()
Is $table->unsignedSmallInteger('code_no', 3)->unique() incorrect?
As stated in the link of my previous post:
if you use any integer blueprint (bigInteger, mediumInteger, tinyInteger, smallInteger, etc...) with any second parameter (other than 0) you are telling Laravel to make an integer with an auto_increment property, this will return: Syntax error or access violation: 1075 Incorrect table definition; there can be only one auto column and it must be defined as a key")
So this syntax is Ok for string but not for integers. I have to admit that when I first investigated the error, I started with my draft file, which was Ok, than I checked migration file, the generated code were as expected, than I have dig deeper and learn that is from Laravel itself.
Gotcha. Feel free to submit a PR with the fix. Otherwise, I will patch this in a future live stream.
@mahfoudfx
There is no such thing as integer length. https://github.com/laravel/framework/issues/1465#issuecomment-18700321
@jasonmccreary can this be closed based on https://github.com/laravel/framework/issues/1465#issuecomment-18700321?
I think the "fix" here is to ignore any length for all integer columns. Blueprint should not generate code which adds a length parameter or chains ->length() to any integer column.