Django : Table doesn't exist

前端 未结 8 1609
再見小時候
再見小時候 2020-11-28 07:45

I dropped some table related to an app. and again tried the syncdb command

python manage.py syncdb

It shows error like

dja         


        
相关标签:
8条回答
  • 2020-11-28 08:19

    This is linked to the migration data in the scripts inside the project not matching with the migration scripts in the database as far as I could tell. I solved this by the following steps :

    1. Delete all the migration scripts under migration folder except __ini__
    2. Make sure that the model.py contains the same structure as the table in the database and managed=True
    3. Remove all Django Created tables like auth_user,... etc
    4. Run the following code
    $ ./manage.py makemigrations
    $ ./manage.py migrate
    

    This will create the migration scripts again and will apply it to your database.

    0 讨论(0)
  • 2020-11-28 08:20

    For those that may still be having trouble (like me), try this out:

    Comment out all the URL's in the main app's urls.py

    Then go ahead and run migrations:

    $ ./manage.py makemigrations
    $ ./manage.py migrate
    

    The problem was alleviated by removing the ()'s

        solved_time = models.DateTimeField('solved time', default=timezone.now())
    

    to

        solved_time = models.DateTimeField('solved time', default=timezone.now)
    

    I got this answer from reddit

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