I am using SQL Server as a default database. I replicated the SQL Server table in the model using inspectdb command. Now, SQL Server table does not have any primary key column. So, django model automatically creates id as a primary key and giving me error while posting the data.
column "id" does not exist
Is there any work around to remove id at the same time not defining primary key on any columns of the model?
from django.db import models
class ImptCustomer(models.Model):
customerid = models.IntegerField(db_column='CustomerId', blank=True, null=True) # Field name made lowercase.
name = models.CharField(db_column='Name', max_length=50, blank=True, null=True) # Field name made lowercase.
phonenumber = models.CharField(db_column='PhoneNumber', max_length=20, blank=True, null=True) # Field name made lowercase.
emailaddress = models.CharField(db_column='EmailAddress', max_length=100, blank=True, null=True) # Field name made lowercase.
streetline = models.CharField(db_column='StreetLine', max_length=50, blank=True, null=True) # Field name made lowercase.
city = models.CharField(db_column='City', max_length=50, blank=True, null=True) # Field name made lowercase.
statecode = models.CharField(db_column='StateCode', max_length=5, blank=True, null=True) # Field name made lowercase.
postalcode = models.CharField(db_column='PostalCode', max_length=20, blank=True, null=True) # Field name made lowercase.
customer_key = models.IntegerField(db_column='Customer_Key', blank=True, null=True, editable = False) # Field name made lowercase.
class Meta:
managed = False
db_table = 'IMPT_Customer'
If you don't explicitly define a primary key, then the id becomes your primary key. So you cannot do that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With