"Unknown command syncdb" running "python manage.py syncdb" - django

I want to create the tables of one database called "database1.sqlite", so I run the command:
python manage.py syncdb
but when I execute the command I receive the following error:
Unknown command: 'syncdb'
Type 'manage.py help' for usage.
But when I run
manage.py help
I don`t see any command suspicious to substitute
python manage.py syncdb
Version of Python I use: 3.4.2 Version of Django I use:1.9
I would be very grateful if somebody could help me to solve this issue.
Regards and thanks in advance

If you look at the release notes for django 1.9, syncdb command is removed.
Please use migrate instead. Moving forward, the migration commands would be as documented here
Please note that the django-1.9 release is not stable as of today.
Edit: Django 1.9 is stable now

the new django 1.9 has removed "syncdb",
run "python manage.py migrate",
if you are trying to create a super user, run "python manage.py createsuperuser"

$python manage.py syncdb is deprecated and not supported now.
So instead of this follow below instructions..
Whatever model you have created:
First run:
$python manage.py makemigrations
After running this command you model will be reflected in a migration.
Then you have to run:
$python manage.py migrate
Then run server:
$python manage.py runserver
Now, your project will run perfectly.

In Django 1.9 onwards syncdb command is removed. So instead of use that one, you can use migrate command,eg: python manage.py migrate.Then you can run your server by python manage.py runserver command.

Django has removed python manage.py syncdb command now you can simply use python manage.py makemigrations followed bypython manage.py migrate. The database will sync automatically.

You can run the command from the project folder as: "python.exe manage.py migrate", from a commandline or in a batch-file.
You could also downgrade Django to an older version (before 1.9) if you really need syncdb.
For people trying to run Syncdb from Visual Studio 2015:
The option syncdb was removed from Django 1.9 (deprecated from 1.7), but this option is currently not updated in the context menu of VS2015.
Also, in case you didn't get asked to create a superuser you should manually run this command to create one: python.exe manage.py createsuperuser

Run the command python manage.py makemigratons,and than python manage.py migrate to sync.

Alternarte Way:
Uninstall Django Module from environment
Edit Requirements.txt a type Django<1.9
Run Install from Requirments option in the enviroment
Try Syncdb again
This worked for me.

I also tried this command. Lastly I found the release note from django
Features removed in 1.9
The syncdb command is removed.
Djnago Releases note 1.9

I had the same problem, the only thing worked for me was this command.
python3 manage.py migrate --run-syncdb
Running this got me this result.
Ranvijays-Mac:djangodemo rana.singh$ python3 manage.py migrate --run-syncdb
Operations to perform:
Synchronize unmigrated apps: messages, staticfiles
Apply all migrations: admin, auth, contenttypes, msg, sessions
Synchronizing apps without migrations:
Creating tables...
Running deferred SQL...
Running migrations:
Applying msg.0001_initial... OK

Related

django runserver : relation "django_migrations" already exists

I have a django project source code, which includes several apps. The source code have been run successfully on one environment, but when transplanted to another device, with the same postgresql version(9.4.4), python version(2.7.5), and django version(1.8.5), but the runserver reports errors like this. The database has been imported in advance.
return self.cursor.execute(sql)
django.db.utils.ProgrammingError: relation "django_migrations" already exists
Try this python manage.py migrate --fake
You can read more about it in official documentation
Try troubleshooting Initial migrations using --fake-initial
python manage.py migrate --fake-initial
https://docs.djangoproject.com/en/1.8/ref/django-admin/#django-admin-option---fake-initial
If you have an empty database you can clear all your migrations and then again run migrations and migrate command.
python manage.py makemigrations
python manage.py migrate

Syncdb not working - django cache issue

I've dropped all tables from my postgres db. Now, while running
python manage.py syncdb
I'm getting error that abc fields doesn't exist in xyz table.
It's probably some sort of django cache issue. Error is of this format:
django.db.utils.ProgrammingError: relation "mmb_data_genre" does not exist
LINE 1: ...b_data_genre"."id", "mmb_data_genre"."genre" FROM "mmb_data_...
Any suggestions how to fix this?
Note - I'm using django 1.8.2 and
python manage.py makemigratons
or
python manage.py runserver
is throwing same error.
syncdb in django 1.8 is merely an alias for the migrate command but with the additional step of creating a superuser.
Deprecated since version 1.7: This command has been deprecated in
favor of the migrate command, which performs both the old behavior as
well as executing migrations.
But syncdb (migrate) should be executed only after you have done makemigrations [app_label] but in your case you seem to have the order in reverse.
Try
./manage.py makemigrations
./manage.py migrate

Django Migrations command workflow

There are three migration commands in Django:
python manage.py makemigrations
python manage.py migrate
python manage.py syncdb
In what order do these commands should be executed in terms of workflow of a basic project?
I am using Version: 1.8
syncdb is deprecated and does the same as migrate.
Whenever you make a change to your models, and when you first create them, each time you'd want to first run makemigrations to create the migration files, then migrate to apply them to your database.

DatabaseError: no such column error

So I have a model that I wanted to add ImageField to, so I typed in
picture = models.ImageField(upload_to='media/images')
I then ran syncdb and went into the shell:
python2 manage.py syncdb
python2 manage.py shell
I then imported the model and tried
"model".objects.get(pk=1)
I get the error:
DatabaseError: no such column: people_people.picture
When I run manage.py sql for the model
"picture" varchar(100) NOT NULL
is in the database.
What solutions do you guys have? I can't delete the data in the database.
As noted in the documentation syncdb doesn't add columns to existing tables, it only creates new tables.
I suggest running
python manage.py sqlall <your_app>
Looking at the sql it outputs for the table you're changing, and then running
python manage.py dbshell
in order to manually issue an ALTER TABLE command.
In future, you might like to use a migration tool like South.
There are two possibilities that to get this error 1) You added extra field to model after doing the syncdb. 2) you added new class to model.py file in django.
Solution for this is:
First install south by using command
for windows: **easy_install south** //for that you need to go to the script folder of python folder in c drive.
for linux: **sudo easy_install south**
Then follow the steps which are included here migration tutorials
step1- python manage.py schemamigration your_app_name --initial
step-2 python manage.py migrate your_app_name
Hope this will help you.
As of 1.7 migrations within Django replaces South.
Create a new set of migration instructions by running the following command in terminal:
$ python manage.py makemigrations
Check the output in the migration folder it creates to make sure they make sense then run the following terminal command to complete the migrations:
$ python manage.py migrate
That's it.
Running migrations this way allows others to implement the same migrations instead of having to manually implement db changes on every machine using the code. On the new machine all they have to run is:
$ python manage.py migrate

Django: no such table: django_session

I have found several topics with this title, but none of their solutions worked for me. I have two Django sites running on my server, both through Apache using different virtualhosts on two ports fed by my Nginx frontend (using for static files). One site uses MySql and runs just fine. The other uses Sqlite3 and gets the error in the title.
I downloaded a copy of sqlite.exe and looked at the mysite.sqlite3 (SQLite database in this directory) file and there is indeed a django_session table with valid data in it. I have the sqlite.exe in my system32 as well as the site-packages folder in my Python path.
Here is a section of my settings.py file:
MANAGERS = ADMINS
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'mysite.sqlite3', # Or path to database file if using sqlite3.
'USER': '', # Not used with sqlite3.
'PASSWORD': '', # Not used with sqlite3.
'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '', # Set to empty string for default. Not used with sqlite3.
}
}
I did use the python manage.py syncdb with no errors and just a "No Fixtures" comment.
Does anyone have any ideas what else might be going on here? I'm considering just transferring everything over to my old pal MySql and just ignoring Sqlite, as really it's always given me some kind of trouble. I was only using it for the benefit of knowing it anyway. I have no overwhelming reason why I should use it. But again, just for my edification does anyone know what this problem is? I don't like to give up.
After made any changes in code, run the following commands
manage.py makemigrations
manage.py migrate
it worked for me.
It could be that the server uses a different working directory than the manage.py command. Since you provide a relative path to the sqlite database, it is created in the working directory. Try it with an absolute path, e.g.:
'NAME': '/tmp/mysite.sqlite3',
Remember that you have to either run ./manage.py syncdb again or copy your current database with the existing tables to /tmp.
If it resolves the error message, you can look for a better place than /tmp :-)
run this in command shell:
python manage.py migrate
This fixed for me.
In case it helps anyone else: the problem for me was that I didn't have the django.contrib.sessions app uncommented in my INSTALLED_APPS. Uncommenting it, and rerunning a syncdb did the trick.
In my case the problem was that I forgot to run manage.py syncdb after I made some changes. When I did that the problem was solved.
When I run "manage.py runserver". If I run when I my current path is not in project dir.(such as python /somefolder/somefolder2/currentprj/manage.py runserver) I'll got the problem like you. solve by cd to project directory before run command.
One other possible cause can come from using:
./manage.py testserver
And then visiting the admin interface. This won't work because testserver creates a completely separate database in memory. If you want to visit the admin interface you need to use runserver.
This can happen if there are pending session migrations.
You have 17 unapplied migration(s). Your project may not work properly
until you apply the migrations for app(s): admin, auth, contenttypes,
sessions.
You can use the following command to run the migrations:
python manage.py migrate
This will fix the issue.
It happens may be beacause of undone migrations
• Executes following commands:
python manage.py showmigrations
python manage.py migrate --fake your_app_name zero
python manage.py showmigrations
• IF you are running on local machine, then remove file named 0001.init.py from migrations folder in your app
• Executes following commands:
python manage.py makemigrations
python manage.py migrate
• then run django server:
python manage.py runserver
had the same issue, my resolution was to simply add 'django.contrib.comments' to INSTALLED_APPS and run ./manage.py syncdb again.
I had similar problem for admin management. After several checks, run "python manage.py migrate" without assign APP's name (get "Apply all migrations: .....), then runserver and up on the web. It worked. I hope this could help.
You have unapplied migrations. your app may not work properly until they are applied.
Run 'python manage.py migrate' to apply them.
python manage.py migrate This one worked for me.
Maybe you have some unmigrated files.
Run
Python manage.py makemigrations appname
python manage.py migrate appname
python manage.py runserver
But if the error still continue
The run python manage.py migrate
The run server
create a schema and add its name under NAME in 'databases'
run manage.py syncdb
I had made some changes in Model which was not migrated to db properly. Using the command
manage.py makemigrations
fixed my problem. I hope this will help someone.
syncdb is obsolete try python manage.py makemigrations and python manage.py migrate solved the problem ,and donot forget to add the app name is the installed app in settings.py
I had the same problem so I ran
heroku run ls
and found that the db.sqlite3 file was missing from the server.
In my case, it was because I exempted it by adding it in .gitignore file.
Maybe it is not getting the path of db. Just add this to your settings.py:
import os
PROJECT_PATH = os.path.dirname(os.path.abspath(__file__))
#modify your db NAME as below:
'NAME': os.path.join(PROJECT_PATH,'mysite.sqlite3'),
In my case I only focused on different project and did not migrate the main application.
so first:
manage.py makemigrations
manage.py migrate
and then to the project's:
manage.py makemigrations <my other project name>
manage.py migrate <my other project name>
Had this problem too. Restarting postgres and apache2 did it for me. Makes me wonder if there was some kind of sqlite process left over which wasn't removed until you fiddled with the files or something.
I had this issue in a different scenario. I am new to Django and cloned a repository from github to practice on it. The file db.sqlite3 was also copied. But there was no django_session in it. When I did
./manage.py showmigrations
.. I found out that there were some migrations. But the tables were missing in sqlite, as I never ran migrate. My issue was resolved when I ran the migrate command. Hope this helps django newbies like me.
./manage.py migrate
Add 'django.contrib.sessions', line in INSTALLED_APPS
Run below commands from django shell
python manage.py makemigrations #check for changes
python manage.py migrate #apply changes in DbSQLite
python manage.py syncdb #sync with database
django_session will appear in database with (session_key, session_data , expire_date)
In my case, I had to erase the 'sessions' entry in the django_migrations table and run makemigrations and migrate afterwards. That created the django_session table.
For me, it was that I updated settings.py, ran the migrations, but the systemd process was still using SQLite because I did not reload it. Doing systemctl restart service_name solved the problem.
And it may be a case you are getting this error because you forget to run query python manage.py migrate before creating super user
If you are tired of using makemigrations and migrate but the error is same no such table django_session. Then just have a look to you code somewhere or the other you using session or calling it. Just comment the code where you are using session and then run the command makemigrations and migrate respectively. It 100% solve your issue.The cause of this error is that you deleted your migrations folder and database file that is the reason you are getting this error.Feel free to ask if problem is not solve
This worked for me.
From https://docs.djangoproject.com/en/2.2/topics/http/sessions/
Using database-backed sessions -
If you want to use a database-backed session, you need to add 'django.contrib.sessions' to your INSTALLED_APPS setting.
Once you have configured your installation, run manage.py migrate to install the single database table that stores session data.
Please try the following command when you change on your code
manage.py makemigrations
manage.py migrate
Simply run this commands
python manage.py makemigrations
python manage.py migrate
python manage.py runserver
it's simple just run the following command
python ./manage.py migrate
python ./manage.py makemigrations AppName