Django manage.py Unknown command: 'syncdb'
Asked Answered
H

6

68

I'm trying to follow this tutorial but I'm stuck on the 5th step.

When I execute

[~/Django Projects/netmag$] python manage.py syncdb

I get the following error message :

Unknown command: 'syncdb'
Type 'manage.py help' for usage.

and here is the output of ./manage.py help does not contain syncdb command. How do I add it?

Thanks for any help!

Edit :

When I run migrate, I get this error :

"Error creating new content types. Please make sure contenttypes " RuntimeError: Error creating new content types. Please make sure contenttypes is migrated before trying to migrate apps individually.

in settings.py :

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.admindocs',
    'blog',
]

Edit 2:

If I remove 'blog', from settings.py :

:~/Django Projects/netmag$ python manage.py migrate blog
CommandError: App 'blog' does not have migrations. 

:~/Django Projects/netmag$ python manage.py makemigrations blog 
App 'blog' could not be found. Is it in INSTALLED_APPS?
Horrible answered 11/2, 2015 at 0:41 Comment(2)
Did you edit the INSTALLED_APPS setting? You should place your app after the all django apps in this list. BTW, I suggest you to use the official tutorial to learn the django: docs.djangoproject.com/en/1.7/intro/tutorial01Infectious
@Infectious Thanks. I will try this tutorial tomorrow. Also I'm adding the INSTALLED_APPS list to the question.Horrible
I
197

syncdb command is deprecated in django 1.7. Use the python manage.py migrate instead.

Infectious answered 11/2, 2015 at 0:44 Comment(5)
Thanks! I'm surprised that Google didn't bring that to my attention :DHorrible
Try to remove your app from the INSTALLED_APPS and run migrate again. The error still occurs?Infectious
I pasted the result in the questionHorrible
Hm. Return the blog back to the INSTALLED_APPS and then run python manage.py migrate contenttypes?Infectious
You can run manage.py migrate --run-syncdb if you have old applications that don't have migrations.Intensifier
D
14

You have to use python manage.py migrate instead rather than python manage.py syncdb

Damick answered 12/4, 2016 at 7:32 Comment(0)
S
13

Run python manage.py makemigrations result below

Migrations for 'blog':
blog/migrations/0001_initial.py:
- Create model Blog

and after that run python manage.py migrate result below

Operations to perform:
Apply all migrations: admin, blog, auth, contenttypes, sessions
Running migrations:
Applying article.0001_initial... OK
Siegbahn answered 24/9, 2016 at 6:42 Comment(0)
N
6

the actual command is :

python manage.py migrate --run-syncdb

It will solve many errors in django like , Operational error ,No Table found in databse etc.

Neuron answered 18/8, 2021 at 20:20 Comment(0)
F
0

You can do it like this in stages, let's say you have an app called "example":

  1. Run python manage.py makemigrations example
  2. A number generates like '0001' get the number
  3. Run python manage.py sqlmigrate example 0001, using the number. Check out the scripts.
  4. Run python manage.py migrate example 0001

You can also look at all your migrations like this: python manage.py showmigrations.
If you don't want to commit it, go to the folder and move it somewhere or delete it before doing step 4.

Fader answered 18/4, 2020 at 3:14 Comment(0)
F
0

However, there is another error that can be happened as strict mode needs to be enabled for MariaDB.

Keep Database connection in the settings.py file as follows:

DATABASES = {
'default': {
    'ENGINE': 'django.db.backends.mysql',
    'NAME': 'test',
    'USER': 'root',
    'PASSWORD': '',
    'HOST': 'localhost',   # Or an IP Address that your DB is hosted on
    'PORT': '3306',
    'OPTIONS': {
        'sql_mode': 'traditional',
    }
}

}

keep in mind about the below code:

'OPTIONS': {
        'sql_mode': 'traditional',
    }

After all, if your DJango version is backdated, "python manage.py syncdb" will work but for an updated version more than or equal to 1.7, please use "python manage.py migrate"

Thanks

Franconian answered 25/3, 2022 at 16:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.