Search code examples
pythondjangodjango-modelsdjango-model-field

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

Solution

  • 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.