Primary Key missing in auto-generated migration
See original GitHub issueUsing Postgres & Piccolo 0.32.0, the auto-generated migrations fail to include the primary key.
Schema:
from piccolo.table import Table
from piccolo.columns import ForeignKey, UUID
class Types(Table):
id = UUID(primary_key=True)
class Things(Table):
type = ForeignKey(references=Types)
When I try to run migrations via:
piccolo migrations new my_app --auto
piccolo migrations forwards all
I get:
Running MigrationManager ...
The command failed.
foreign key constraint "things_type_fkey" cannot be implemented
DETAIL: Key columns "type" and "id" are of incompatible types: integer and uuid.
Looking at the generated migration, I see:
class Types(Table, tablename="types"):
pass
Adding the PK manually to the migration fixes the issue:
class Types(Table, tablename="types"):
id = UUID(primary_key=True)
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (5 by maintainers)
Top Results From Across the Web
Use Table in Entity with no Primary Key (Using Entity Code ...
1 Answer 1 ... If the field contains unique data you can mark it as Key in EF and disable all automatic migrations....
Read more >Auto Generating Migrations — Alembic 1.9.0 documentation
Autogenerate can't currently, but will eventually detect: Some free-standing constraint additions and removals may not be supported, including PRIMARY KEY, ...
Read more >Auto-generated primary keys: UUID, serial or identity column?
This article explores the old question what to use for autogenerated primary keys: UUID, serial or identity column?
Read more >UUID primary key leads to delayed anonymous unique ...
Describe the bug Summary: When using UUID as primary key in SQL Alchemy, ... autogenerates again, the constraint continues to be "missing".
Read more >Troubleshooting migration tasks in AWS Database Migration ...
To solve this issue, the current approach is to first precreate the tables and primary keys in the target database. Then use a...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I think the issue here is the
ForeignKey
should be created with typeUUID
, otherwise it can’t store the reference to aUUID
primary key.This should work - I’ll investigate what went wrong.
@adriangb That’s fine I think. We didn’t really have an issue for that PR. Thanks for reporting it.