After make migrations , i tried to do migrate, but i am getting the django.db.utils.ProgrammingError: multiple default values specified for column "id" of table "products_customer"
But iam remove this customer table from models.py how i solve this ?
models.py
from django.db import models
from django.contrib.auth.models import User
from django.db.models.signals import post_save
from django.dispatch import receiver
# Create your models here.
class product(models.Model):
product_id = models.IntegerField(primary_key=True)
product_name = models.CharField(max_length=255)
product_price = models.FloatField()
product_stock = models.IntegerField()
product_image = models.CharField(max_length=2500)
class order(models.Model):
order_id = models.IntegerField(primary_key=True)
product_id = models.ForeignKey(product,on_delete=models.CASCADE)
user = models.ForeignKey(User,on_delete=models.CASCADE)
order_quantity = models.IntegerField()
order_total = models.IntegerField()
order_shipped = models.BooleanField()
class address(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
house_name = models.CharField(max_length=255, blank=True)
town = models.CharField(max_length=255, blank=True)
post_office = models.CharField(max_length=255, blank=True)
pincode = models.CharField(max_length=255)
district = models.CharField(max_length=255, blank=True)
land_mark = models.CharField(max_length=255, blank=True)
phone = models.CharField(max_length=15, blank=True)
@receiver(post_save, sender=User)
def create_user_address(sender, instance, created, **kwargs):
if created:
address.objects.create(user=instance)
@receiver(post_save, sender=User)
def save_user_address(sender, instance, **kwargs):
instance.address.save()
Error message
PS C:\Users\sujit\OneDrive\Desktop\project\django> python manage.py makemigrations No changes detected PS C:\Users\sujit\OneDrive\Desktop\project\django> python manage.py migrate
Operations to perform: Apply all migrations: admin, auth, contenttypes, products, sessions Running migrations: Applying products.0004_auto_20211114_2342...Traceback (most recent call last): File "C:\Users\sujit\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\backends\utils.py", line 84, in _execute return self.cursor.execute(sql, params) psycopg2.errors.SyntaxError: multiple default values specified for column "id" of table "products_customer"
The above exception was the direct cause of the following exception: Traceback (most recent call last): File "C:\Users\sujit\OneDrive\Desktop\project\django\manage.py", line 22, in main() File "C:\Users\sujit\OneDrive\Desktop\project\django\manage.py", line 18, in main execute_from_command_line(sys.argv) File "C:\Users\sujit\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\management_init_.py", line 419, in execute_from_command_line utility.execute() File "C:\Users\sujit\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\management_init_.py", line 413, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "C:\Users\sujit\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\management\base.py", line 354, in run_from_argv self.execute(*args, **cmd_options) File "C:\Users\sujit\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\management\base.py", line 398, in execute output = self.handle(*args, **options) File "C:\Users\sujit\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\management\base.py", line 89, in wrapped res = handle_func(*args, **kwargs) File "C:\Users\sujit\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\management\commands\migrate.py", line 244, in handle post_migrate_state = executor.migrate( File "C:\Users\sujit\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\migrations\executor.py", line 117, in migrate state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial) File "C:\Users\sujit\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\migrations\executor.py", line 147, in _migrate_all_forwards state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial) File "C:\Users\sujit\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\migrations\executor.py", line 227, in apply_migration state = migration.apply(state, schema_editor) File "C:\Users\sujit\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\migrations\migration.py", line 126, in apply operation.database_forwards(self.app_label, schema_editor, old_state, project_state) File "C:\Users\sujit\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\migrations\operations\fields.py", line 104, in database_forwards schema_editor.add_field( File "C:\Users\sujit\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\backends\base\schema.py", line 522, in add_field self.execute(sql, params) File "C:\Users\sujit\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\backends\base\schema.py", line 145, in execute cursor.execute(sql, params) File "C:\Users\sujit\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\backends\utils.py", line 98, in execute return super().execute(sql, params) File "C:\Users\sujit\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\backends\utils.py", line 66, in execute return self._execute_with_wrappers(sql, params, many=False, executor=self._execute) File "C:\Users\sujit\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\backends\utils.py", line 75, in _execute_with_wrappers return executor(sql, params, many, context) File "C:\Users\sujit\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\backends\utils.py", line 84, in _execute return self.cursor.execute(sql, params) File "C:\Users\sujit\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\utils.py", line 90, in exit raise dj_exc_value.with_traceback(traceback) from exc_value File "C:\Users\sujit\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\backends\utils.py", line 84, in _execute return self.cursor.execute(sql, params) django.db.utils.ProgrammingError: multiple default values specified for column "id" of table "products_customer"
mamemigrationsyou digging into migration files to see changes? All looks fine?