Skip to content
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

How to make primary key unsigned in an existing table? #2135

Open
Zorinik opened this issue Nov 3, 2022 · 4 comments
Open

How to make primary key unsigned in an existing table? #2135

Zorinik opened this issue Nov 3, 2022 · 4 comments
Labels

Comments

@Zorinik
Copy link

Zorinik commented Nov 3, 2022

Good morning,
since as of phinx 0.13 PKs are unsigned by default, I would like to write a migration to update existing table and make their PKs unsigned, in order to preserve consistency between old and new future tables. I can't find a solution for doing this in the docs, there is a way? Thanks

@dereuromark
Copy link
Member

#2159 will make it possible to restore previous behavior for now

We should also add docs on how to overcome those upgrading challenges however
I agree, that we need some info on that.

@MasterOdin
Copy link
Member

You'd want to use the changeColumn method . Assuming you're trying to change the default primary key that's created:

->changeColumn('id', 'integer', ['identity' => true, 'signed' => true])

Before:

mysql> SHOW COLUMNS FROM foo;
+-------+--------------+------+-----+---------+----------------+
| Field | Type         | Null | Key | Default | Extra          |
+-------+--------------+------+-----+---------+----------------+
| id    | int unsigned | NO   | PRI | NULL    | auto_increment |
+-------+--------------+------+-----+---------+----------------+
1 rows in set (0.02 sec)

After:

mysql> SHOW COLUMNS FROM foo;
+-------+--------------+------+-----+---------+----------------+
| Field | Type         | Null | Key | Default | Extra          |
+-------+--------------+------+-----+---------+----------------+
| id    | int          | NO   | PRI | NULL    | auto_increment |
+-------+--------------+------+-----+---------+----------------+
1 rows in set (0.01 sec)

@dereuromark Do you have a set place in mind to put this info? Just in the changelog for the next release that has feature flags?

@dereuromark
Copy link
Member

We might also want to add the details in docs and from release notes more like link to it.

@MasterOdin
Copy link
Member

MasterOdin commented Jan 6, 2023

I guess add a note to it in the link I posted for this? I don't know another place that'd really fit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants