- changed milestone to 0.8.0final
- marked as major
Columns with primary_key=True and a ForeignKey should have autoincrement=False by default
(original reporter: holm) When creating columns that are both integer, part of the primary key and a foreign key, should have autoincrement set to False by default. Currently it is easy to forget to set autoincrement=False, which causes the column to have an auto incrementer set. This rarely (ever?) makes sense for columns that have a foreign key, so the default could be changed.
Having the autoincrement set without knowing, could lead to very subtle bugs, where the value could not be set, and instead an auto-generated value used.
Comments (4)
-
repo owner -
Account Deleted (original author: holm) Hi Mike
Terribly sorry about this. I seem to have gotten confused about some error messages we where seing for our CI builds.
It does seem to work as you described (and as documented). Sorry to waste your time.
Christian
-
repo owner - changed status to wontfix
hey no problem at all, glad it's working out for you.
mike
-
repo owner - removed milestone
Removing milestone: 0.8.0final (automated comment)
- Log in to comment
this already is the behavior of autoincrement. Here's a test:
Here's the output of the actual CREATE statements when run on 0.7:
as you can see, on postgresql only "a" gets SERIAL, and on MySQL only "a" gets "AUTO_INCREMENT". "b.id" is not considered to be an autoincrement column due to the foreign key.
The docs (http://www.sqlalchemy.org/docs/core/schema.html#sqlalchemy.schema.Column) try very hard to make this clear:
If you can clarify if you're seeing something different that would be great else I'll soon resolve this as "worksforme".