Django migrate : doesn't create tables

前端 未结 10 1700
独厮守ぢ
独厮守ぢ 2021-01-31 18:03

After some errors, I dropped my database, deleted all my migration files (I left init.py). Now, when I run

python migrate.py makemigrations   /         


        
相关标签:
10条回答
  • 2021-01-31 18:39
    python manage.py migrate --fake APPNAME zero
    

    This will make your migration to fake. Now you can run the migrate script

    python manage.py migrate APPNAME
    

    Tables will be created and you solved your problem.. Cheers!!!

    0 讨论(0)
  • 2021-01-31 18:41

    Please check if you are using multiple databases in your project. If multiple databases configured, check the default database is the one you are looking for.

    If default and your expected database are different, run below command pointing to your db configuration.

    python manage.py migrate $app_name --database $dbname_from_setting

    Hope this helps.

    0 讨论(0)
  • 2021-01-31 18:42

    I face same issue:

    python manage.py migrate poll
    Operations to perform:
      Apply all migrations: poll
    Running migrations:
      No migrations to apply.
    

    Follow these steps to create tables for your app.

    Go to your app folder

    1.delete migration folder.

    2.python manage.py makemigrations.

    3 Rename 0001_initial.py file to 0001_initial_manual.py.

    4 python manage.py migrate APPNAME.

    After this my tables created smoothly.

    python manage.py migrate poll
    Operations to perform:
      Apply all migrations: poll
    Running migrations:
      Applying poll.0002_initial... OK
    
    0 讨论(0)
  • 2021-01-31 18:44

    The answer to this depends if you already have a history of migrations in your app folder. In my case I didn't...I think I deleted original migration scripts.

    So following the Django docs, I did the following:

    1. Comment out new updates in models.py
    2. Follow section Adding migrations to apps...
    3. Create migrations for what is already existing:

      python manage.py makemigrations yourapp

    4. Do fake applying of these migrations (below singles that the tables already exist and not to try to recreate):

      python manage.py migrate --fake-initial

    5. Uncomment changes in model.py
    6. Follow steps in section Workflow ...

      python manage.py makemigrations yourapp

      python manage.py migrate

    0 讨论(0)
  • 2021-01-31 18:50

    This is how I got @JulienD's answer to work:

    1. I added metadata to my model def in models.py:

    class thing(models.Model): name = models.CharField(max_length=200) class Meta: app_label = 'things' managed = True

    1. Execute:

    python manage.py makemigrations

    1. Execute:

    python manage.py migrate

    After that python manage.py showmigrations shows the migrations and the admin site started working.

    0 讨论(0)
  • 2021-01-31 18:52

    I had manually deleted one of the tables and the trick that worked for me was to execute the following steps:

    1. Removed the migrations folder.
    2. deleted the migrations from db: DELETE from django_migrations WHERE app='alerts_db';
    3. python manage.py migrate --run-syncdb' before
    4. python manage.py makemigrations 'app_name'
    5. python manage.py migrate --fake

    Note: earlier I was not executing the #3 step and the table was not getting created. my django version: v3.0.5

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