简体   繁体   中英

Django CharField primary key doesn't work, creating rowid primary key automatically

I am using Django models for a SQLite database.

I defined CharField primary key (for example the name of attribute A ) but the physical database synced by Django shows another primary key rowid instead of A .

I tried dropping the table and re-sync a couple of time but still the same.

Why?

class TestTable(models.Model):
    A = models.CharField(max_length=10, primary_key=True, db_column='A')

----------------------Edit------------------------

Django version is 1.8.3

SQLITE databases always create a rowid column by default. This is the actual primary key SQLITE uses for manage the database. This is different from what you see in other SQL databases, but SQLITE is pretty different in more things.

For more info look at https://www.sqlite.org/rowidtable.html

PS I know that this is 2 years late, but it might help someone if not OP.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM