0

I made some changes to my model.py file... I added another field (fds_name):

from django.db import models

class funds(models.Model):
    fds_symbol  = models.CharField(max_length=5)
    fds_name  = models.CharField(max_length=128)

I ran the South schema migration command, and it detected the change and made a migration:

/var/www/finance/finance-env/bin/python3 manage.py schemamigration corefinance --auto
tail corefinance/migrations/0002_auto__add_funds.py
        models = {
            'corefinance.funds': {
                'Meta': {'object_name': 'funds'},
                'fds_name': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
                'fds_symbol': ('django.db.models.fields.CharField', [], {'max_length': '5'}),
                'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
            }
        }

        complete_apps = ['corefinance']

However, when I run the migration, it says there's nothing to migrate, and I can see that the database is still missing the new field.

/var/www/finance/finance-env/bin/python3 manage.py migrate corefinance
Running migrations for corefinance:
- Nothing to migrate.
 - Loading initial data for corefinance.
Installed 0 object(s) from 0 fixture(s)
Jeremy T
  • 758
  • 2
  • 9
  • 23

2 Answers2

1

It's probably because between the --initial migration and the next schemamigration you have to persist the actual migration to the db issuing the command python manage.py migrate corefinance.

After doing that first migration then you may add another field, do and schemamigration --auto and commit it to the db again by doing python manage.py migrate corefinance

dhana
  • 6,487
  • 4
  • 40
  • 63
  • I did see your other answer, but I'm pretty sure that I did run that command: /var/www/finance/finance-env/bin/python3 manage.py migrate corefinance – Jeremy T Jun 20 '14 at 17:57
  • ok remove the migration folder in your corefinance and also remove the last created row(0002_auto__add_funds) from the south table and again run the initial migration and then migrate it. – dhana Jun 20 '14 at 18:12
  • Thanks, that worked, but I had to actually drop the funds table before the migration would run. What happens in the future when I've got important data in the funds table? – Jeremy T Jun 20 '14 at 18:20
  • You should see this http://stackoverflow.com/questions/4625712/whats-the-recommended-approach-to-resetting-migration-history-using-django-sout. – dhana Jun 20 '14 at 18:28
1

This solution is a bit more finnicky than dhana's answer, but it works. You can manually change the database schema through your database admin interface, then run a fake migration. By doing this, Django will think the schemamigration has been applied, and all necessary database changes will have already been made.

Greg
  • 1,845
  • 2
  • 16
  • 26