0

I want to run some migrations. Everything seems to run correctly until I want to run my website. There is a column missing. I can fix it manually, but I want to understand the mistake I make when running the migration.

This is a part of my migraton file where the column is added:

migrations.CreateModel(
        name='PostTranslation',
        fields=[
            ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
            ('language_code', models.CharField(db_index=True, max_length=15, verbose_name='Language', choices=settings.LANGUAGES)),
            ('title', models.CharField(max_length=255, verbose_name='Title')),
            ('slug', models.SlugField(verbose_name='slug', blank=True)),
            ('abstract', djangocms_text_ckeditor.fields.HTMLField(verbose_name='Abstract')),
            ('meta_description', models.TextField(default=b'', verbose_name='Post meta description', blank=True)),
            ('meta_keywords', models.TextField(default=b'', verbose_name='Post meta keywords', blank=True)),
            ('meta_title', models.CharField(default=b'', help_text='used in title tag and social sharing', max_length=255, verbose_name='Post meta title', blank=True)),
            ('post_text', djangocms_text_ckeditor.fields.HTMLField(default=b'', verbose_name='Text', blank=True)),
            ('master', models.ForeignKey(related_name='translations', editable=False, to='djangocms_blog.Post', null=True)),
        ],
        options={
            'db_table': 'djangocms_blog_post_translation',
            'verbose_name': 'blog article Translation',
            'default_permissions': (),
        },
        bases=(models.Model,),

These are the commands I'm running:

python manage.py migrate djangocms_blog 0001

In this first step there is a creation of the column meta_title
If I run my migration the shell outputs:

    Operations to perform:
  Target specific migration: 0001_initial, from djangocms_blog
Running migrations:
  Unapplying djangocms_blog.0005_auto_20150115_1444... OK
  Unapplying djangocms_blog.0004_auto_20150108_1435... OK
  Unapplying djangocms_blog.0003_auto_20141201_2252... OK
  Unapplying djangocms_blog.0002_post_sites... OK

At this point I would expect the meta_title column is created in the database... But nothing happened... I'm sure I'm in the right database and my settings are correct. Because If i create the meta_title column manually, the websites runs withouth errors.

Can somebody help me?

Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895
RVE
  • 328
  • 4
  • 17
  • You've asked Django to migrate backwards so it's unapplying all the migrations from 5 to 2. And you haven't shown a migration which adds a column. – Daniel Roseman Jan 15 '15 at 15:38
  • Well the migration file where the CreateModel is located is shown here (meta_title). So it's in the 0001_initial migration (where the error is located), for that reason I only posted the output of that migration. – RVE Jan 15 '15 at 15:58
  • Yes but that is creating as part of the initial setup, not adding it later. And can you not see that the output contains the text "unapplying"? You had already run up to migration 5, you asked Django to *rewind* the migrations back down to 1. – Daniel Roseman Jan 15 '15 at 16:19
  • Well I even tried to run all migrations until number 5 and they say: OK. But the column is not created yet – RVE Jan 16 '15 at 15:55
  • Because you've never added it! Somehow you've got to a state where the migrations do not reflect the state of your database - perhaps you created the database manually, added a field in the model code, and only then ran makemigrations. As noted in [the docs](https://docs.djangoproject.com/en/1.7/topics/migrations/#adding-migrations-to-apps), Django does not actually examine the db tables to ensure they match. You will need to add the column manually in the db, or drop your db completely and run migrations from scratch. – Daniel Roseman Jan 16 '15 at 16:51

0 Answers0