aWebDeveloper
aWebDeveloper

Reputation: 38352

django admin don't show primary key in forms

I am using django 1.4. I have a primary key filed called city_id. when i go to add a new record in django admin, it asks me to enter the primary key. why is it doing so.

class CityMaster(models.Model):
    city_id = models.IntegerField(primary_key=True)

Upvotes: 1

Views: 980

Answers (2)

bambata
bambata

Reputation: 313

If you do so, it means no automatic key will be provided by django which is why you have to provide it by hands.

Upvotes: 1

Matthias
Matthias

Reputation: 13222

You need a primary key. If you want Django to handle this value for you then use an AutoField.

city_id = models.AutoField(primary_key=True)

Upvotes: 2

Related Questions