newbie difficulty using south with pycharm - DatabaseError: no such table: south_migrationhistory

12,895

Solution 1

South uses a table if its own to keep track of which migrations have been applied. Before you can apply any migrations, this must have been created, using python ./manage.py syncdb.

As well as for setting up south, you will find syncdb sometimes necessary for non-south apps in your project, such as the very common django.contrib.auth.

Note that as a convenience, you can run both in one go like this

python ./manage.py syncdb --migrate

Solution 2

My latest (unsuccessful) effort was the following

  1. Create application – synch db – superuser created
  2. Test run –admin screen shows basic tables
  3. Add south, and syncdb from command line with manage.py syncdb – south_migrationhistory table created. Add basic vanilla model
  4. Tried various combinations of manage.py syncdb –manage, and schemamigration from Pycharm (if run from within pycharm a migrations directory is created within the app – if run from the command line the directory does not seem to be created.)
  5. Django admin screen shows table – but if I try to edit the table it says that it doesn’t exist
  6. Check database structure using SQLite browser - table for newly created model doesn’t exist

I’m starting to think that the whole thing is not worth the time wasting hassle – maybe I’m better off just modifying the tables in SQLite browser

Share:
12,895
Marg
Author by

Marg

Updated on June 17, 2022

Comments

  • Marg
    Marg about 2 years

    I'm using sqlite3 and pycharm to learn more about django, and googled to find that south is recommended to make it easier to modify models after they have been created.

    I'm trying to follow the advice on http://south.aeracode.org/docs/tutorial/part1.html#starting-off.

    The most success I've had so far is to create a simple model and run syncdb before adding south to installed_apps. That way the intial tables are created and I get a chance to create a super user. (Django admin seems to fret if there are no users).

    Then I add south to installed_apps, and run django_manage.py schemamigration bookmarks --initial

    It seems to work fine. A new directory is created called migrations with a couple of files in it in my app folder and an encouraging message. "Created 0001_initial.py. You can now apply this migration with: ./manage.py migrate bookmarks"

    The next step - django_manage.py" migrate bookmarks generates the following error message django.db.utils.DatabaseError: no such table: south_migrationhistory.

    I thought that table would be created in the first schememigration step. What am I missing? Can anyone help?

    Marg

  • Marg
    Marg over 12 years
    Thanks jpic and kdt - now I definitely have a south_migrationhistory table, and I even get a feedback message when I ran synchmigratioin from pycharm saying that my model had been added to the migration (or words to that effect) - but now the admin screen is a big blank welcome message telling me to create a database.
  • kdt
    kdt over 12 years
    What you're trying to do isn't exotic or complicated, and it should work. I suggest that you work through it at the command line, leave PyCharm out of the equation until it's working. One thing to clarify is that 'schemamigration' doesn't touch your database, it just generates the .py files in migrations/ -- you have to use 'migrate' after that to actually update the database.
  • Marg
    Marg over 12 years
    Thanks for clarifying that a two step process is required.
  • Marg
    Marg over 12 years
    Thanks for clarifying that a two step process is required. I now get to the stage of adding the migrations directory with schemamigration followed by the first migration, but still not there with making changes to model. Running schemamigration --auto seems to succesfully recognise the new field, and wants a default value supplied, but then the following migration falls over with message "django.db.utils.DatabaseError: table "bookmarks_link" already exists". Of course it exists - it's the one I'm trying to change. I still seem to be missing something.
  • Marg
    Marg over 12 years
    Found the answers elewhere on the forum - first about the [need to use --fake for the first migration] (stackoverflow.com/questions/3567256/south-django-migrate) and then about a suitable sequence of commands to sort things out when migrations get out of synch with database
  • kdt
    kdt over 12 years
    Marg: it's great that you found a solution. On stackoverflow, you can post an answer to your own question, which makes it easier for others with the same problem to find it (often there are lots of comments and an answer buried in a comment is hard to find).
  • jpic
    jpic over 12 years
    Marg: please close the question, you'd do so by accepting kdt's answer. I just came back to see why this wasn't answered and i should have spent the time helping an open question rather than reading your updates. Thank you in advance :)
  • andilabs
    andilabs over 10 years
    so refering to this official South tutorial (south.readthedocs.org/en/latest/tutorial/…) python ./manage.py syncdb --migrate should substitute: ./manage.py schemamigration southtut --initial and ./manage.py migrate southtut am I right?