#26730 closed Cleanup/optimization (duplicate)
Make AutoField consistent between postgresql and mysql
| Reported by: | Veit Heller | Owned by: | nobody | 
|---|---|---|---|
| Component: | Database layer (models, ORM) | Version: | 1.9 | 
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | no | Needs documentation: | no | 
| Needs tests: | no | Patch needs improvement: | no | 
| Easy pickings: | no | UI/UX: | no | 
Description
The problem
Currently, (Big)*AutoField becomes an integer AUTO_INCREMENT field in MySQL whereas it becomes a serial in PostgreSQL (which is a positive integer).
The resolution?
Update the MySQL version to use the serial datatype (which is just a macro for bigint unsigned not null auto_increment unique).
Caveats
The MySQL serial datatype might introduce too many unwanted restrictions. If the community thinks this might break too much code, I would suggest to at least make the MySQL version unsigned too, to increase the consistency between the DB adapters.
Change History (3)
comment:1 by , 9 years ago
| Component: | Uncategorized → Database layer (models, ORM) | 
|---|---|
| Resolution: | → duplicate | 
| Status: | new → closed | 
| Type: | Uncategorized → Cleanup/optimization | 
comment:2 by , 9 years ago
FTR, I took a look at #56 during the PyCon sprints. The only sensible way to implement it is IMO a PositiveAutoField.
The primary key column on PostgreSQL is an integer (-2147483648 to +2147483647) and the related sequence a bigint (-9223372036854775808 to +9223372036854775807) with min_value=1, max_value=9223372036854775807. https://www.postgresql.org/docs/9.5/static/datatype-numeric.html
SQLite doesn't allow unsigned integers for PK columns.
MySQL supports integer UNSIGNED for PK, but that's not backwards compatible to the existing code base.
comment:3 by , 9 years ago
Thanks for the heads-up. I will look into how to resolve this on my own then.
Duplicate of #56