[Support request] No primary key for a model
See original GitHub issueHi Charles,
I’ve got a table which logs keywords, schema is:
class Keyword(Model):
name = CharField(null=False)
created = DateTimeField(null=False, default=datetime.utcnow)
class Meta:
indexes = (
(('created', 'name'), False)
)
In short, I want to drop the auto-generated primary key column (id). How do I prevent it from being readded in subsequent db creations? I’ve taken a look into the manual and not found the syntax.
In long, in the database however it has added an id column and associated pkey index. This table now has 35 million rows and that pkey index taking up 10gb in ram. I’ve taken a look into the code and it looks safe to drop the column, we only perform an aggregate query on the table in any case:
Keyword.select(Keyword.created, Keyword.name).where(Keyword.created > 3_days)
OR Keyword.select().where(Keyword.created > 3_days).count()
Neither of these should need a primary key as we can get exact duplicates (35mil rows are for 3 days of data).
Many thanks, Alex
PS. It would also be awesome to be able to name index constraints, getting a few problems when running schema migrations because of name mismatches between environments.
Issue Analytics
- State:
- Created 8 years ago
- Comments:6 (5 by maintainers)
Top GitHub Comments
For models with no primary key, simply specify
primary_key=False
in the innerMeta
class:If you want a multi-column primary key you can write:
Thanks @coleifer for this answer of yours - it helped me greatly now, three years later. 👍 (I was struggling with peewee trying to retrieve data from a non-existing sequence as below)
Applying the
primary_key = False
to the inner class fixed the issue.