"python manage.py syncdb" does not create tables

I ran first

python manage.py syncdb 

and he created a database and tables for me, then I tried to add more applications, and here is what I did:

create applications

 python manage.py startapp newapp 

Then I added 'newapp' to INSTALLED_APPS in settings.py:

 INSTALLED_APPS = ( 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'newapp', ) 

Finally I ran syncdb :

 python manage.py syncdb 

and here is the result:

 Creating tables ... Installing custom SQL ... Installing indexes ... Installed 0 object(s) from 0 fixture(s) 

I checked my db and there is no table named newapp , there is no table name including newapp .

+7
python django
source share
6 answers

If you run:

 python manage.py inspectdb > somefile.txt 

You can quickly check if your database structure matches your django models.

+3
source share

I also ran into this problem and was able to work around it by deleting the migration folder in my application. Somehow, it had already been created and tricked syncdb into believing that it had already been fully ported, but these migration scenarios actually did nothing useful. Obviously, do not try this if you really have migrations that you want to keep, but I worked with a completely new application and models.

+6
source share

I have tried most of the above ideas:

  • make sure models.py imported (verified that the module is executing during makemigrate),
  • delete migrations folder
  • managed = True (default is always)
  • used python manage.py inspectdb (which correctly dumped the table if I created it manually).

The key was to just run makemigrations in the application separately:

python manage.py makemigrations <app_name>

as part of the mamemigrations step. Then you do

python manage.py migrate

normally.

(Applies to Django 1.10 using Postgres 9.5).

Django Documentation

Credit, related post

+4
source share

I have the same problem, but I did not have any "migration". I solved it as shown below.

I just added app_label with the model code,

 class MyModel(models.Model): ... class Meta: managed = True # add this app_label = 'myapp' # & this 

Also, make sure it can be detected by specifying it in myapp/models/__init__.py

 from model_file.py import MyModel 
+1
source share

I had the same problem and noticed that he created a db.sqlite3 file that did not seem empty:

 $ ls -l -rw-r--r-- 1 sauron staff 122880 Jul 31 01:22 db.sqlite3 

I tried to start sqlite again using the file name as an argument, and this worked:

 $ sqlite3 db.sqlite3 SQLite version 3.7.13 2012-07-17 17:46:21 Enter ".help" for instructions Enter SQL statements terminated with a ";" sqlite> .schema CREATE TABLE "auth_group" ( "id" integer NOT NULL PRIMARY KEY, "name" varchar(80) NOT NULL UNIQUE ); ... many rows ... 
0
source share

You must use this command

 python manage.py migrate 

where did you run syncdb from the location where manage.py is located

0
source share

All Articles