user10989738
user10989738

Reputation: 81

Django Auto add id field in database i don't want it

Django auto add id field in database i don't want to add id field in my database please help

 fields=[
            ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),

Upvotes: 0

Views: 772

Answers (1)

Endre Both
Endre Both

Reputation: 5740

If you prefer to designate another model field as the primary key, add primary_key=True to the desired field. See related Django docs. E.g.

username = models.CharField(max_length=50, primary_key=True)

If you don't need a primary key at all, maybe a relational table is not the best place to save your data. Django needs a primary key in its tables and doesn't provide a way to prevent its creation.

Upvotes: 2

Related Questions