Ad

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')),
Ad

Answer

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.

Ad
source: stackoverflow.com
Ad