django.db.utils.IntegrityError: UNIQUE constraint failed: rango_category__new.slug

前端 未结 7 2423
渐次进展
渐次进展 2020-12-01 05:47

I\'m learning Django from Tango with Django but I keep getting this error when I type:

python manage.py makemigrations rango
python manage.py migrate
         


        
7条回答
  •  猫巷女王i
    2020-12-01 06:19

    This means a slug should be unique. You may have some data in your model. You need to delete all the data in that model and you need to migrate again.

    In this situation, you have two ways to fix the error;

    1. You need to delete it from the Django admin site. More often than not, it may give an error when you are trying to open the model.

    2. Open command prompt

    move to project -> py manage.py shell -> from yourappname.models import modelname -> modelname.objects.delete()
    

    Here if you define a product manager for your model. Then you have to define a delete function. Later you should makemigrate, migrate and continue with the second way

提交回复
热议问题