0

So I know there are already a ton of questions by people who changed a model and then failed to apply the migration to their database. However, in my case, I know for a fact that the migration was applied, as I can see the new table data.

Basically, I installed django-cms, and then I added a field to the djangocms_column plugin's models.py to allow me to add a Bootstrap class name to my columns (e.g. col-md-4, col-md-6, etc.).

if hasattr(settings, "COLUMN_CLASS_CHOICES"):
    CLASS_CHOICES = settings.COLUMN_CLASS_CHOICES
else:
    CLASS_CHOICES = (
        ('col-md-1', _("col-md-1")),
        ('col-md-2', _("col-md-2")),
        ('col-md-3', _('col-md-3')),
        ('col-md-4', _("col-md-4")),
        ('col-md-5', _('col-md-5')),
        ('col-md-6', _("col-md-6")),
        ('col-md-7', _('col-md-7')),
        ('col-md-8', _('col-md-8')),
        ('col-md-9', _('col-md-9')),
        ('col-md-10', _('col-md-10')),
        ('col-md-11', _('col-md-11')),
        ('col-md-12', _('col-md-12')),
        ('', _('none')),
    )

...

@python_2_unicode_compatible
class Column(CMSPlugin):
    """
    A Column for the MultiColumns Plugin
    """

    width = models.CharField(_("width"), choices=WIDTH_CHOICES, default=WIDTH_CHOICES[0][0], max_length=50)

    """
    This is the new field:
    """
    bs_class = models.CharField(_("bs_class"), choices=CLASS_CHOICES, default=CLASS_CHOICES[0][0], max_length=50)

    def __str__(self):
        return u"%s" % self.get_width_display()

I then ran ./manage.py makemigrations and then ./manage.py migrate, and now the table looks like this:

sqlite> select * from djangocms_column_column;
cmsplugin_ptr_id  bs_class    width     
----------------  ----------  ----------
3                 col-md-1    33%       
5                 col-md-1    33%       
7                 col-md-1    33%       
19                col-md-1    33%       
21                col-md-1    33%       
23                col-md-1    33% 

Yet when I try to access the test server, I still get the following error:

OperationalError at /en/
no such column: djangocms_column_column.bs_class
Request Method: GET
Request URL:    http://localhost:8000/en/
Django Version: 1.7.10
Exception Type: OperationalError
Exception Value:    
no such column: djangocms_column_column.bs_class

And, yes, I've tried deleting the database and running ./manage.py migrate, but the site still displays the same error. Is there a special migration procedure one must use to modify plugins installed in the ./env/lib/python2.7/site-packages folder?

Lèse majesté
  • 7,923
  • 2
  • 33
  • 44

2 Answers2

1

So I actually figured out what was causing this behavior. In designing my gulp tasks, I restructured the project folder, putting all of my django-created files inside of a src subdirectory.

I did this thinking it'd be easier to watch my app files for changes this way without unintentionally triggering my watch tasks when gulpfile.js or files in bower_components were modified. (Ultimately, it didn't matter, since my globs were more specific than just the django project root.)

This wouldn't have been a problem except that settings.DATABASES['default']['NAME'] was the relative path project.db. As a result, when I ran ./manage.py migrate from within the /src directory, it performed the migrations on /src/project.db. And when I ran src/manage.py migrate from the parent directory, the migrations were performed on /project.db. The djangocms app itself was using the latter, while I'd been performing all of my migrations on the former.

So the lessons here are:

  • Make sure your sqlite file is specified using an absolute path.
  • When you encounter seemingly inexplicable migration issues, check to make sure you don't have multiple .db files floating around in your workspace.
Lèse majesté
  • 7,923
  • 2
  • 33
  • 44
0

Have you tried deleting migrations in migration folder inside the app?

Prashant Shukla
  • 742
  • 2
  • 6
  • 19
  • There aren't any migrations in the app folder. The only migration that didn't come with django-cms was the one that added that column, and it's in the `./env/lib/python2.7/site-packages/djangocms_column/migrations_django` folder. I'm not sure how deleting it would fix the error. – Lèse majesté Oct 31 '15 at 09:37
  • while running makemigration doesn't it shows **Migrations for 'books': 0001_auto.py:** these 0001_auto.py files are the migrations which are stored in migration folder which reside inside the app. – Prashant Shukla Oct 31 '15 at 09:50