-
Notifications
You must be signed in to change notification settings - Fork 889
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unsigned primary keys #250
Comments
I think not really, because the autogen'd column type is hardcoded right in the I'm sure you've tried some of this, I post here my method if it is of some help. Method 1) Preferred, since I think it will be compatible with all DB adapters. Right after creating the table, just modify the public function up()
{
[... create the table ...]
$col_id = new Phinx\Db\Table\Column();
$col_id->setIdentity(true); // Needed to be AUTO_INCREMENT
$col_id->setType("integer"); // Or it can also be "biginteger"
$col_id->setOptions(["signed" => false]); // Makes the column unsigned
$my_table->changeColumn("id", $col_id)->save();
} Method 2) The obvious ALTER TABLE. Here the syntax is for MySQL only public function up()
{
[... create the table ...]
$this->execute("ALTER TABLE `my_table` CHANGE `id` `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT");
} |
Thanks! I had ended up going with the second option, the ALTER route. I wish I could just use the the packaged methods, but I've found that I end up spending far too much time toying, testing, and tweaking as opposed to just running an execute() command and being done with it. Thanks again! |
thx @twoixter . I'd recommend to use either of those methods for now. |
Alternative method overriding Phinx classes. |
This is a feature I miss. Doesn't necessarily break the app, but it hurts inside knowing that all my auto-increment id's will be signed for no practical reason. |
@robmorgan I would love to see this feature. Sure @twoixter solution works great (thanks!) but it would be nicer to have the possibility to configure it directly especially in such a nice library like yours :) |
Just posted a small update for @twoixter solution: https://gist.github.com/adayth/f0ead7bd210e3968208e#gistcomment-1585602 |
Who came up with the brilliant idea to set primary keys as signed in the first place, that's one of the reasons I'm starting to think raw SQL files for migrations wasn't such a bad idea after all... Overall Phinx feeling -> This is just retarded. |
Hi @bubach that was me and it's why I no longer work on this project anymore. You might want to check out this instead: https://flywaydb.org/ 👍 |
…igned Due to 0.13 breaking change in Phinx library, type of primary key changed from 'int' to 'unsigned int'. This breaks our migrations because we always reference primary keys in foreign keys as 'int'. Phinx provides backward compatible flag to turn on the former behaviour (in 'feature-flags' settings) see: - https://book.cakephp.org/phinx/0/en/configuration.html#feature-flags - cakephp/phinx#250
Is there a way to cause the autogen'd primary key ('id') to be unsigned?
The text was updated successfully, but these errors were encountered: