I am trying to deploy my Django-cms site on Heroku, and I'm really struggling with migrations. I'm running django 1.7.7 and django-cms 3.1.0. I don't have any data to migrate, so I just want to create the empty tables.
With a fresh Heroku Postgres database:
heroku run python manage.py migrate contenttypes
output:
Operations to perform:
Apply all migrations: contenttypes
Running migrations:
Applying contenttypes.0001_initial...Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/app/.heroku/python/lib/python3.4/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/app/.heroku/python/lib/python3.4/site-packages/django/core/management/__init__.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/app/.heroku/python/lib/python3.4/site-packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **options.__dict__)
File "/app/.heroku/python/lib/python3.4/site-packages/django/core/management/base.py", line 338, in execute
output = self.handle(*args, **options)
File "/app/.heroku/python/lib/python3.4/site-packages/django/core/management/commands/migrate.py", line 161, in handle
executor.migrate(targets, plan, fake=options.get("fake", False))
File "/app/.heroku/python/lib/python3.4/site-packages/django/db/migrations/executor.py", line 68, in migrate
self.apply_migration(migration, fake=fake)
File "/app/.heroku/python/lib/python3.4/site-packages/django/db/migrations/executor.py", line 96, in apply_migration
if self.detect_soft_applied(migration):
File "/app/.heroku/python/lib/python3.4/site-packages/django/db/migrations/executor.py", line 140, in detect_soft_applied
apps = project_state.render()
File "/app/.heroku/python/lib/python3.4/site-packages/django/db/migrations/state.py", line 75, in render
"for more" % new_unrendered_models
django.db.migrations.state.InvalidBasesError: Cannot resolve bases for [<ModelState: 'djangocms_link.Link'>, <ModelState: 'djangocms_text_ckeditor.Text'>, <ModelState: 'djangocms_file.File'>, <ModelState: 'djangocms_inherit.InheritPagePlaceholder'>, <ModelState: 'djangocms_column.MultiColumns'>, <ModelState: 'djangocms_column.Column'>, <ModelState: 'djangocms_googlemap.GoogleMap'>, <ModelState: 'djangocms_flash.Flash'>, <ModelState: 'djangocms_snippet.SnippetPtr'>, <ModelState: 'djangocms_video.Video'>, <ModelState: 'djangocms_teaser.Teaser'>, <ModelState: 'djangocms_picture.Picture'>]
This can happen if you are inheriting models from an app with migrations (e.g. contrib.auth)
in an app with no migrations; see https://docs.djangoproject.com/en/1.7/topics/migrations/#dependencies for more
What I don't understand is that contenttypes doesn't depend on any of those models in the djangocms plugins. If I try to migrate any of the plugins first, I get a stack trace and this:
RuntimeError: Error creating new content types. Please make sure contenttypes is migrated before trying to migrate apps individually.
UPDATE: Following the documentation for the various django-cms plugins, I added MIGRATION_MODULES to settings.py. Now when I run:
heroku run python manage.py makemigrations djangocms_text_ckeditor
a migration is created:
Migrations for 'djangocms_text_ckeditor':
0001_initial.py:
- Create model Text
Sounds great! But...
heroku run python manage.py migrate djangocms_text_ckeditor
output:
Operations to perform:
Apply all migrations: (none)
Running migrations:
No migrations to apply.
Your models have changes that are not yet reflected in a migration, and so won't be applied.
Run 'manage.py makemigrations' to make new migrations, and then re-run 'manage.py migrate' to apply them.
Traceback (most recent call last):
File "/app/.heroku/python/lib/python3.4/site-packages/django/contrib/contenttypes/models.py", line 44, in get_for_model
ct = self._get_from_cache(opts)
File "/app/.heroku/python/lib/python3.4/site-packages/django/contrib/contenttypes/models.py", line 34, in _get_from_cache
return self.__class__._cache[self.db][key]
KeyError: 'default'
During handling of the above exception, another exception occurred:
[long stack trace ommitted]
As stated in djangocms_link module documentation - https://github.com/divio/djangocms-link
If using Django 1.7 add 'djangocms_link': 'djangocms_link.migrations_django', to MIGRATION_MODULES
And same for djangocms_file module
So basically you should have in your settings.py
MIGRATION_MODULES = {
'djangocms_link': 'djangocms_link.migrations_django',
'djangocms_file': 'djangocms_file.migrations_django'
}
Related
I have a development database I was working on and I had issues with the migrations taking for adding a foreignkey field. I ended up having to blow away the database after clearing my migrations folder out and redoing it. So now I have one migration file...
The problem is, I pulled code to my test server, and now that database is VERY out of sync (it's not, django thinks it is. It really just needs a table added and a field). Though running make migrations breaks as the migration folder I had pushed was clear of all but one migration and does not jive with the migration folder on the test server.
Any ideas as to how I can reconcile this, it is my test data so blowing away the database here and starting new isn't an issue, but this will be a huge issue again when I push to production (and cannot blow away that database). Maybe dump the data/database using pg_dump, blow away the database, run migrations and load the data back via the dump file?
EDIT:
I did try to create my own migration manually since I was in a state where makemigrations said nothing new was done. My migration file:
The error it gives me (no idea what this is telling me)
Operations to perform:
Apply all migrations: filer, sessions, admin, auth, contenttypes, swsite, registration, easy_thumbnails
Running migrations:
Rendering model states... DONE
Applying swsite.0001_initial... OK
Applying swsite.0002_auto_20170302_0841...Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/lib64/python2.7/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
utility.execute()
File "/usr/lib64/python2.7/site-packages/django/core/management/__init__.py", line 345, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/lib64/python2.7/site-packages/django/core/management/base.py", line 348, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/lib64/python2.7/site-packages/django/core/management/base.py", line 399, in execute
output = self.handle(*args, **options)
File "/usr/lib64/python2.7/site-packages/django/core/management/commands/migrate.py", line 200, in handle
executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial)
File "/usr/lib64/python2.7/site-packages/django/db/migrations/executor.py", line 92, in migrate
self._migrate_all_forwards(plan, full_plan, fake=fake, fake_initial=fake_initial)
File "/usr/lib64/python2.7/site-packages/django/db/migrations/executor.py", line 121, in _migrate_all_forwards
state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
File "/usr/lib64/python2.7/site-packages/django/db/migrations/executor.py", line 198, in apply_migration
state = migration.apply(state, schema_editor)
File "/usr/lib64/python2.7/site-packages/django/db/migrations/migration.py", line 115, in apply
operation.state_forwards(self.app_label, project_state)
File "/usr/lib64/python2.7/site-packages/django/db/migrations/operations/fields.py", line 50, in state_forwards
state.models[app_label, self.model_name_lower].fields.append((self.name, field))
KeyError: (u'swsite', u'cesiumentity')
The migration:
# -*- coding: utf-8 -*-
# Generated by Django 1.9.6 on 2017-03-02 15:41
from __future__ import unicode_literals
from django.db import migrations, models
import django.contrib.gis.db.models.fields
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('swsite', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='ZoneEntity',
fields=[
('zone_number', models.CharField(max_length=100, primary_key=True, serialize=False)),
('mpoly', django.contrib.gis.db.models.fields.PolygonField(srid=4326)),
('created_at', models.DateField(auto_now_add=True)),
('updated_at', models.DateField(auto_now=True)),
],
),
migrations.AddField(
model_name='cesiumentity',
name='zone_id',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='swsite.ZoneEntity'),
),
]
If this is something you can do manually (add one field and one table), you can set the migrations as completed in the migration table (either all of them, or just the ones that are causing issues).
This might help you out:
https://www.algotech.solutions/blog/python/django-migrations-and-how-to-manage-conflicts/
As you are the single developer for the project, python manage.py migrate should be fine if you are pushing migrations in the git repo.
Or you can ignore migrations folder by adding it to .gitignore and run python manage.py makemigrations on test server every time db is modified and finally u can execute python manage.py migrate to reflect changes in the db.
I wanted to validate if there is a bug in makemigrations in django 1.8 with sql lite or I am doing something wrong.
After I Dropped my DB and deleted all migration folders. I run
python manage.py makemigrations
python manage.py migrate
DB gets created no problems.
2.I have to modify existing model in one of the apps (app abc)
I perform my change and run again
python manage.py makemigrations
3.it doesn't find any changes
then I run same thing again but with app name
python manage.py makemigrations abc
4.It does some updates in migrations , I believe it recreates all the tables and not just my change !!!!
5.Then I execute
python manage.py migrate
and getting error that table already exists .
Is it a bug in django framework or I am doing something wrong and there is a reason why it behaves this way?
Copy paste from my shell starting from step 2:
(mrp) C:\Users\I812624\dev\mrp\src>python manage.py makemigrations
No changes detected
(mrp) C:\Users\I812624\dev\mrp\src>python manage.py makemigrations purchase
Migrations for 'purchase':
0001_initial.py:
- Create model PO
- Create model POmaterial
(mrp) C:\Users\I812624\dev\mrp\src>python manage.py migrate
Operations to perform:
Synchronize unmigrated apps: customer, manufacture, product, django_filters, a
utofixture, staticfiles, messages, smart_selects, watson, sales, item, django_co
untries, mptt, inventory, django_select2, production, main, crispy_forms
Apply all migrations: purchase, vendor, sessions, admin, sites, flatpages, con
tenttypes, auth, registration
Synchronizing apps without migrations:
Creating tables...
Running deferred SQL...
Installing custom SQL...
Running migrations:
Rendering model states... DONE
Applying purchase.0001_initial...Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\I812624\dev\mrp\lib\site-packages\django\core\management\__init
__.py", line 338, in execute_from_command_line
utility.execute()
File "C:\Users\I812624\dev\mrp\lib\site-packages\django\core\management\__init
__.py", line 330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\I812624\dev\mrp\lib\site-packages\django\core\management\base.p
y", line 390, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\I812624\dev\mrp\lib\site-packages\django\core\management\base.p
y", line 441, in execute
output = self.handle(*args, **options)
File "C:\Users\I812624\dev\mrp\lib\site-packages\django\core\management\comman
ds\migrate.py", line 221, in handle
executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial)
File "C:\Users\I812624\dev\mrp\lib\site-packages\django\db\migrations\executor
.py", line 110, in migrate
self.apply_migration(states[migration], migration, fake=fake, fake_initial=f
ake_initial)
File "C:\Users\I812624\dev\mrp\lib\site-packages\django\db\migrations\executor
.py", line 147, in apply_migration
state = migration.apply(state, schema_editor)
File "C:\Users\I812624\dev\mrp\lib\site-packages\django\db\migrations\migratio
n.py", line 115, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, projec
t_state)
File "C:\Users\I812624\dev\mrp\lib\site-packages\django\db\migrations\operatio
ns\models.py", line 59, in database_forwards
schema_editor.create_model(model)
File "C:\Users\I812624\dev\mrp\lib\site-packages\django\db\backends\base\schem
a.py", line 282, in create_model
self.execute(sql, params or None)
File "C:\Users\I812624\dev\mrp\lib\site-packages\django\db\backends\base\schem
a.py", line 107, in execute
cursor.execute(sql, params)
File "C:\Users\I812624\dev\mrp\lib\site-packages\django\db\backends\utils.py",
line 79, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "C:\Users\I812624\dev\mrp\lib\site-packages\django\db\backends\utils.py",
line 64, in execute
return self.cursor.execute(sql, params)
File "C:\Users\I812624\dev\mrp\lib\site-packages\django\db\utils.py", line 97,
in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "C:\Users\I812624\dev\mrp\lib\site-packages\django\db\backends\utils.py",
line 62, in execute
return self.cursor.execute(sql)
File "C:\Users\I812624\dev\mrp\lib\site-packages\django\db\backends\sqlite3\ba
se.py", line 316, in execute
return Database.Cursor.execute(self, query)
django.db.utils.OperationalError: table "purchase_po" already exists
To answer my own question .
So what I have figured out . I believe the problem is that I have originally deleted the folders migrations and when I run makemigrations without specifying particular app it does create a DB but it dosent create the folder makemigrations with ____init____.py inside it.
solution each time when you drop db and delete migrations folder for whatever reason dont just delete the migrations folder but only its content excluding init file.
Or when you do delete the folder run make migrations individually for each app as #MicroPyramid suggested.
Without doing deeper investigation it looks to me or as confusing designed behaviour or a bug from Django side.
I'm trying to deploy a Django (1.8) app to Heroku, runtime Python 3.4.2. The app runs succesfully (except the fact that tables are not created), but when trying run the syncdb I get the following error:
Running `python manage.py syncdb` attached to terminal... up, run.5851
/app/.heroku/python/lib/python3.4/site-packages/django/core/management
/commands/syncdb.py:24: RemovedInDjango19Warning: The syncdb command
will be removed in Django 1.9
warnings.warn("The syncdb command will be removed in Django 1.9", RemovedInDjango19Warning)
Traceback (most recent call last):
File "/app/.heroku/python/lib/python3.4/site-packages/django/db/migrations/loader.py", line 157, in check_key
return list(self.graph.root_nodes(key[0]))[0]
IndexError: list index out of range
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/app/.heroku/python/lib/python3.4/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/app/.heroku/python/lib/python3.4/site-packages/django /core/management/__init__.py", line 330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/app/.heroku/python/lib/python3.4/site-packages/django/core/management/base.py", line 390, in run_from_argv
self.execute(*args, **cmd_options)
File "/app/.heroku/python/lib/python3.4/site-packages/django/core/management/base.py", line 441, in execute
output = self.handle(*args, **options)
File "/app/.heroku/python/lib/python3.4/site-packages/django/core/management/commands/syncdb.py", line 25, in handle
call_command("migrate", **options)
File "/app/.heroku/python/lib/python3.4/site-packages/django/core/management/__init__.py", line 120, in call_command
return command.execute(*args, **defaults)
File "/app/.heroku/python/lib/python3.4/site-packages/django/core/management/base.py", line 441, in execute
output = self.handle(*args, **options)
File "/app/.heroku/python/lib/python3.4/site-packages/django/core/management/commands/migrate.py", line 93, in handle
executor = MigrationExecutor(connection, self.migration_progress_callback)
File "/app/.heroku/python/lib/python3.4/site-packages/django/db/migrations/executor.py", line 19, in __init__
self.loader = MigrationLoader(self.connection)
File "/app/.heroku/python/lib/python3.4/site-packages/django/db/migrations/loader.py", line 47, in __init__
self.build_graph()
File "/app/.heroku/python/lib/python3.4/site-packages/django/db/migrations/loader.py", line 287, in build_graph
parent = self.check_key(parent, key[0])
File "/app/.heroku/python/lib/python3.4/site-packages/django/db/migrations/loader.py", line 164, in check_key
raise ValueError("Dependency on app with no migrations: %s" % key[0])
ValueError: Dependency on app with no migrations: authentication
I'm using sqlite.
On your dev machine, create your migrations with python manage.py makemigrations. Then, assuming your migrations folders are pushed to heroku, on heroku run python manage.py migrate instead of python manage.py syncdb. See the docs.
I hade to enter the heroku's machine bash :
heroku run bash
and then make the makemigrations:
heroku run python manage.py makemigrations
Finally,
heroku run python manage.py migrate
For me i solved this issue by using same command what we use in our local server with prefix "heroku run" that's it..
for eg:-
python manage.py makemigrations
it will work in our local but for heroku, like this :-
heroku run python manage.py makemigrations
I am trying to add south to my project on Heroku. I followed the following steps.
heroku run easy_install South
Added 'south' in INSTALLED_APPS in settings.py
Then
heroku run ./manage.py syncdb
heroku run ./manage.py convert_to_south sheets
Traceback
Running `./manage.py convert_to_south sheets` attached to terminal... up, run.2005
Creating migrations directory at '/app/sheets/migrations'...
Creating __init__.py in '/app/sheets/migrations'...
+ Added model sheets.Sheets
+ Added model sheets.UserSheets
+ Added M2M table for users on sheets.UserSheets
+ Added model sheets.SheetScribble
+ Added model sheets.SheetScribbleComment
+ Added model sheets.Tasks
+ Added model sheets.TaskComment
Created 0001_initial.py. You can now apply this migration with: ./manage.py migrate sheets
- Soft matched migration 0001 to 0001_initial.
Running migrations for sheets:
- Nothing to migrate.
- Loading initial data for sheets.
Installed 0 object(s) from 0 fixture(s)
App 'sheets' converted. Note that South assumed the application's models matched the database
(i.e. you haven't changed it since last syncdb); if you have, you should delete the sheets/migrations
directory, revert models.py so it matches the database, and try again.
then when I try to convert my second app to south,
heroku run ./manage.py convert_to_south scribbler
I get this error
Running `./manage.py convert_to_south scribbler` attached to terminal... up, run.6046
Creating migrations directory at '/app/scribbler/migrations'...
Creating __init__.py in '/app/scribbler/migrations'...
+ Added model scribbler.ScribbleMedia
+ Added model scribbler.Scribble
+ Added model scribbler.Tag
+ Added M2M table for scribbles on scribbler.Tag
+ Added model scribbler.SharedScribble
+ Added M2M table for users_favored on scribbler.SharedScribble
+ Added model scribbler.ScribbleComment
+ Added model scribbler.Connections
+ Added unique constraint for ['following', 'followers'] on scribbler.Connections
+ Added model scribbler.UserProfile
+ Added model scribbler.Invitation
+ Added model scribbler.Notifications
Created 0001_initial.py. You can now apply this migration with: ./manage.py migrate scribbler
Traceback (most recent call last):
File "./manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/app/.heroku/venv/lib/python2.7/site-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
utility.execute()
File "/app/.heroku/venv/lib/python2.7/site-packages/django/core/management/__init__.py", line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/app/.heroku/venv/lib/python2.7/site-packages/django/core/management/base.py", line 196, in run_from_argv
self.execute(*args, **options.__dict__)
File "/app/.heroku/venv/lib/python2.7/site-packages/django/core/management/base.py", line 232, in execute
output = self.handle(*args, **options)
File "/app/.heroku/venv/lib/python2.7/site-packages/south/management/commands/convert_to_south.py", line 87, in handle
delete_ghosts=options.get("delete_ghosts", False),
File "/app/.heroku/venv/lib/python2.7/site-packages/django/core/management/__init__.py", line 150, in call_command
return klass.execute(*args, **defaults)
File "/app/.heroku/venv/lib/python2.7/site-packages/django/core/management/base.py", line 232, in execute
output = self.handle(*args, **options)
File "/app/.heroku/venv/lib/python2.7/site-packages/south/management/commands/migrate.py", line 108, in handle
ignore_ghosts = ignore_ghosts,
File "/app/.heroku/venv/lib/python2.7/site-packages/south/migration/__init__.py", line 193, in migrate_app
applied_all = check_migration_histories(applied_all, delete_ghosts, ignore_ghosts)
File "/app/.heroku/venv/lib/python2.7/site-packages/south/migration/__init__.py", line 74, in check_migration_histories
m = h.get_migration()
File "/app/.heroku/venv/lib/python2.7/site-packages/south/models.py", line 34, in get_migration
return self.get_migrations().migration(self.migration)
File "/app/.heroku/venv/lib/python2.7/site-packages/south/models.py", line 31, in get_migrations
return Migrations(self.app_name)
File "/app/.heroku/venv/lib/python2.7/site-packages/south/migration/base.py", line 61, in __call__
self.instances[app_label] = super(MigrationsMetaclass, self).__call__(app_label_to_app_module(app_label), **kwds)
File "/app/.heroku/venv/lib/python2.7/site-packages/south/migration/base.py", line 89, in __init__
self.set_application(application, force_creation, verbose_creation)
File "/app/.heroku/venv/lib/python2.7/site-packages/south/migration/base.py", line 161, in set_application
raise exceptions.NoMigrations(application)
south.exceptions.NoMigrations: Application '<module 'sheets' from '/app/sheets/__init__.py'>' has no migrations.
I am not sure what the problem is.
You shouldn't be running those commands ON heroku. You should be doing that on your local environment, pushing them to heroku, then running the migrate commands.
It has an "ephemeral filesystem" which probably cleared between those two commands. So south has a record of a 0001 migration, but it doesn't exist.
I'm not sure why it's being thrown during the "convert_to_south" command (some new south feature?), but that's my best guess.
Try doing it locally, committing the migration files, then proceeding to run the migrate commands on heroku.
I have a new Django 1.3 project and app that I've created. I added south to my settings.py and have not yet run syncdb. When I execute the following commands per the South tutorial and documentation, I received the error shown below.
Any thoughts on what's causing the problem? Update: Not properly installing South (see answer).
Is South 0.7.3 compatible with Django 1.3? Update: Yes.
Commands Executed and South Error
$ python ./manage.py schemamigration qexpenses --initial
Creating migrations directory at '/Users/matthew/development/quest-projects/qexpense-tracker/quexptrkr/../quexptrkr/qexpenses/migrations'...
Creating __init__.py in '/Users/matthew/development/quest-projects/qexpense-tracker/quexptrkr/../quexptrkr/qexpenses/migrations'...
+ Added model qexpenses.Buyer
+ Added model qexpenses.Vendor
+ Added model qexpenses.Department
+ Added model qexpenses.Project
+ Added model qexpenses.PurchaseType
+ Added model qexpenses.PurchaseOrder
Created 0001_initial.py. You can now apply this migration with: ./manage.py migrate qexpenses
(qexpense-tracker)matthew#Matthew-Rankins-MacBook-Pro:~/development/quest-projects/qexpense-tracker/quexptrkr
$ python ./manage.py migrate
Traceback (most recent call last):
File "./manage.py", line 14, in <module>
execute_manager(settings)
File "/Users/matthew/.virtualenvs/qexpense-tracker/lib/python2.7/site-packages/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/Users/matthew/.virtualenvs/qexpense-tracker/lib/python2.7/site-packages/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/matthew/.virtualenvs/qexpense-tracker/lib/python2.7/site-packages/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Users/matthew/.virtualenvs/qexpense-tracker/lib/python2.7/site-packages/django/core/management/base.py", line 220, in execute
output = self.handle(*args, **options)
File "/Users/matthew/.virtualenvs/qexpense-tracker/lib/python2.7/site-packages/south/management/commands/migrate.py", line 105, in handle
ignore_ghosts = ignore_ghosts,
File "/Users/matthew/.virtualenvs/qexpense-tracker/lib/python2.7/site-packages/south/migration/__init__.py", line 171, in migrate_app
applied = check_migration_histories(applied, delete_ghosts, ignore_ghosts)
File "/Users/matthew/.virtualenvs/qexpense-tracker/lib/python2.7/site-packages/south/migration/__init__.py", line 72, in check_migration_histories
for h in histories:
File "/Users/matthew/.virtualenvs/qexpense-tracker/lib/python2.7/site-packages/django/db/models/query.py", line 107, in _result_iter
self._fill_cache()
File "/Users/matthew/.virtualenvs/qexpense-tracker/lib/python2.7/site-packages/django/db/models/query.py", line 772, in _fill_cache
self._result_cache.append(self._iter.next())
File "/Users/matthew/.virtualenvs/qexpense-tracker/lib/python2.7/site-packages/django/db/models/query.py", line 273, in iterator
for row in compiler.results_iter():
File "/Users/matthew/.virtualenvs/qexpense-tracker/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 680, in results_iter
for rows in self.execute_sql(MULTI):
File "/Users/matthew/.virtualenvs/qexpense-tracker/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 735, in execute_sql
cursor.execute(sql, params)
File "/Users/matthew/.virtualenvs/qexpense-tracker/lib/python2.7/site-packages/django/db/backends/util.py", line 34, in execute
return self.cursor.execute(sql, params)
File "/Users/matthew/.virtualenvs/qexpense-tracker/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py", line 234, in execute
return Database.Cursor.execute(self, query, params)
django.db.utils.DatabaseError: no such table: south_migrationhistory
(qexpense-tracker)matthew#Matthew-Rankins-MacBook-Pro:~/development/quest-projects/qexpense-tracker/quexptrkr
$
Configuration
I'm running OS X 10.6.7. Below is the output of pip 1.0 requirements.txt for my virtualenv:
$ cat requirements.txt
Django==1.3
South==0.7.3
distribute==0.6.15
virtualenv==1.6
virtualenvwrapper==2.6.3
wsgiref==0.1.2
Ken Cochrane's answer to the StackOverflow question How Come My South Migrations Doesn't Work for Django held the key.
For a new Django project and app, I had to perform the following steps:
Add South to INSTALLED_APPS in settings.py, but do not add your apps
Run syncdb to add the Django and South tables to the database. South modifies syncdb, so it's important to have South in your INSTALLED_APPS.
Add apps to INSTALLED_APPS in settings.py
Run python manage.py schemamigration app_name --initial for each app
Run python manage.py migrate app_name
Read the instructions—No, all of the instructions
I was so excited to start using South that I skipped reading the installation documentation. I simply installed South using pip install south and then just added it to my INSTALLED_APPS. That was my mistake.
The Configuring Your Django Installation section of the installation documentation states:
Once South is added in, you’ll need to run ./manage.py syncdb to make the South migration-tracking tables (South doesn’t use migrations for its own models, for various reasons).