I can't change my models and create new tables if the old ones are deleted. I am using south and when I just added a new model to my models and created a new one, I used
python manage.py migrate logins --fake
Running migrations for logins:
- Nothing to migrate.
- Loading initial data for logins.
Installed 0 object(s) from 0 fixture(s)
Liubous-MacBook-Pro:Django_project_for_EGG yudasinal1$ python manage.py syncdb
Syncing...
Creating tables ...
Installing custom SQL ...
Installing indexes ...
Installed 0 object(s) from 0 fixture(s)
Synced:
> django.contrib.admin
> django.contrib.auth
> django.contrib.contenttypes
> django.contrib.sessions
> django.contrib.messages
> django.contrib.staticfiles
Not synced (use migrations):
- logins
- south
(use ./manage.py migrate to migrate these)
Then I said:
python manage.py migrate logins
Running migrations for logins:
- Nothing to migrate.
- Loading initial data for logins.
Installed 0 object(s) from 0 fixture(s)
Nothing was actually changed and created, as when I accessed admin, it was written, that the table does not exist. So I decided to delete my database and create a new one, that failed as well:
python manage.py sql logins
BEGIN;
CREATE TABLE "logins_department" (
"id" integer NOT NULL PRIMARY KEY,
"name" varchar(200) NOT NULL
)
;
CREATE TABLE "logins_game" (
"id" integer NOT NULL PRIMARY KEY,
"name_of_the_game" varchar(200) NOT NULL
)
;
CREATE TABLE "logins_info_game" (
"id" integer NOT NULL PRIMARY KEY,
"info_id" integer NOT NULL,
"game_id" integer NOT NULL REFERENCES "logins_game" ("id"),
UNIQUE ("info_id", "game_id")
)
;
CREATE TABLE "logins_info_department" (
"id" integer NOT NULL PRIMARY KEY,
"info_id" integer NOT NULL,
"department_id" integer NOT NULL REFERENCES "logins_department" ("id"),
UNIQUE ("info_id", "department_id")
)
;
CREATE TABLE "logins_info" (
"id" integer NOT NULL PRIMARY KEY,
"organization_name" varchar(200) NOT NULL,
"user_name" varchar(200) NOT NULL,
"password" varchar(200) NOT NULL
)
;
CREATE TABLE "logins_customuser_department" (
"id" integer NOT NULL PRIMARY KEY,
"customuser_id" integer NOT NULL,
"department_id" integer NOT NULL REFERENCES "logins_department" ("id"),
UNIQUE ("customuser_id", "department_id")
)
;
CREATE TABLE "logins_customuser_game" (
"id" integer NOT NULL PRIMARY KEY,
"customuser_id" integer NOT NULL,
"game_id" integer NOT NULL REFERENCES "logins_game" ("id"),
UNIQUE ("customuser_id", "game_id")
)
;
CREATE TABLE "logins_customuser" (
"user_ptr_id" integer NOT NULL PRIMARY KEY REFERENCES "auth_user" ("id")
)
;
COMMIT;
python manage.py syncdb
Syncing...
Creating tables ...
Installing custom SQL ...
Installing indexes ...
Installed 0 object(s) from 0 fixture(s)
Synced:
> django.contrib.admin
> django.contrib.auth
> django.contrib.contenttypes
> django.contrib.sessions
> django.contrib.messages
> django.contrib.staticfiles
Not synced (use migrations):
- logins
- south
(use ./manage.py migrate to migrate these)
Liubous-MacBook-Pro:Django_project_for_EGG yudasinal1$ python manage.py schemamigration south --initial
+ Added model south.MigrationHistory
Created 0003_initial.py. You can now apply this migration with: ./manage.py migrate south
I migrated them(error again):
python manage.py migrate south
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
utility.execute()
File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Library/Python/2.7/site-packages/django/core/management/base.py", line 242, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Library/Python/2.7/site-packages/django/core/management/base.py", line 285, in execute
output = self.handle(*args, **options)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/South-0.8-py2.7.egg/south/management/commands/migrate.py", line 111, in handle
ignore_ghosts = ignore_ghosts,
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/South-0.8-py2.7.egg/south/migration/__init__.py", line 200, in migrate_app
applied_all = check_migration_histories(applied_all, delete_ghosts, ignore_ghosts)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/South-0.8-py2.7.egg/south/migration/__init__.py", line 79, in check_migration_histories
for h in histories:
File "/Library/Python/2.7/site-packages/django/db/models/query.py", line 96, in __iter__
self._fetch_all()
File "/Library/Python/2.7/site-packages/django/db/models/query.py", line 854, in _fetch_all
self._result_cache = list(self.iterator())
File "/Library/Python/2.7/site-packages/django/db/models/query.py", line 220, in iterator
for row in compiler.results_iter():
File "/Library/Python/2.7/site-packages/django/db/models/sql/compiler.py", line 710, in results_iter
for rows in self.execute_sql(MULTI):
File "/Library/Python/2.7/site-packages/django/db/models/sql/compiler.py", line 781, in execute_sql
cursor.execute(sql, params)
File "/Library/Python/2.7/site-packages/django/db/backends/util.py", line 69, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "/Library/Python/2.7/site-packages/django/db/backends/util.py", line 53,
return self.cursor.execute(sql, params)
File "/Library/Python/2.7/site-packages/django/db/utils.py", line 99, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/Library/Python/2.7/site-packages/django/db/backends/util.py", line 53, in execute
return self.cursor.execute(sql, params)
File "/Library/Python/2.7/site-packages/django/db/backends/sqlite3/base.py", line 450, in execute
return Database.Cursor.execute(self, query, params)
django.db.utils.OperationalError: no such table: south_migrationhistory
And so none of the tables were actually created.
Here are my models:
from django.db import models
from django.contrib.auth.models import User, UserManager
class Department(models.Model):
name = models.CharField(max_length=200)
def __unicode__(self):
return self.name
class Game(models.Model):
name_of_the_game = models.CharField(max_length=200)
def __unicode__(self):
return self.name_of_the_game
class Info(models.Model):
organization_name = models.CharField(max_length=200)
user_name = models.CharField(max_length=200)
password = models.CharField(max_length=200)
game = models.ManyToManyField(Game)
department = models.ManyToManyField(Department)
def __unicode__(self):
return self.organization_name+ ': '+ 'user name: ' +self.user_name+ ', '+ 'password: ' + self.password
class CustomUser(User):
department = models.ManyToManyField(Department)
game = models.ManyToManyField(Game)
objects = UserManager()
This command is wrong:
python manage.py schemamigration south --initial
schemamigration
creates files that describe the migration. South already ships its own migration files with the release.What you need is to create the migrations for your own app:
python manage.py schemamigration logins --initial
Then, I would reinstall south, just it case it broke when you created that migration:
pip uninstall south && pip install south
EDIT A pip uninstall doesn't remove that migration so you need to delete those files manually:
rm -rf /<OS dependent>/python2.7/site-packages/south
Finally apply the migrations:
python manage.py syncdb && python manage.py migrate