django.db.utils.IntegrityError:

后端 未结 10 505
忘掉有多难
忘掉有多难 2021-01-21 07:47

django.db.utils.IntegrityError: The row in table \'main_tutorial\' with primary key \'1\' has an invalid foreign key: main_tutorial.tutorial_series_id contains a

相关标签:
10条回答
  • 2021-01-21 08:05

    You can simply delete all the objects in the main_tutorial table from django shell:

    1. goto command prompt
    2. python manage.py shell
    3. from main.models import Tutorial
    4. Tutorial.objects.all().delete()

    (main being the app name here)

    This will delete all the objects in the Tutorial table and then makemigrations and migrate and it should work just fine.

    0 讨论(0)
  • 2021-01-21 08:06

    Try to delete all the migration files exept __init__.py and also delete db.sqlite3. After that run makemigrations and migrate again

    0 讨论(0)
  • 2021-01-21 08:09

    Delete migration files from the folder except

    __init__.py
    

    Then:

    python manage.py makemigrations
    python manage.py migrate
    
    0 讨论(0)
  • 2021-01-21 08:16

    Try using on_delete = models.CASCADE without a default parameter.

    0 讨论(0)
提交回复
热议问题