0

I have a django migration:

0020_delete_cesiumentity

which deletes a table... then I rebuild it (this is was trying to fix a previous problem I had) with this migration I created:

0021_cesiumentity.py

# -*- coding: utf-8 -*-
# Generated by Django 1.9.5 on 2016-12-19 22:45
from __future__ import unicode_literals

import django.contrib.gis.db.models.fields
from django.db import migrations, models


class Migration(migrations.Migration):

    dependencies = [
        ('swsite', '0020_delete_cesiumentity'),
    ]

    operations = [
        migrations.CreateModel(
            name='CesiumEntity',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('be_number', models.CharField(max_length=100)),
                ('image_id', models.CharField(blank=True, max_length=100, null=True)),
                ('mission_id', models.CharField(blank=True, max_length=100, null=True)),
                ('product_type', models.CharField(blank=True, max_length=100, null=True)),
                ('polarization', models.CharField(blank=True, max_length=256, null=True)),
                ('mode_id', models.CharField(blank=True, max_length=100, null=True)),
                ('mode_name', models.CharField(blank=True, max_length=100, null=True)),
                ('acquisition_type', models.CharField(blank=True, max_length=100, null=True)),
                ('image_size_samples', models.CharField(blank=True, max_length=100, null=True)),
                ('image_size_lines', models.CharField(blank=True, max_length=100, null=True)),
                ('sample_spacing_range', models.CharField(blank=True, max_length=100, null=True)),
                ('line_spacing_azimuth', models.CharField(blank=True, max_length=100, null=True)),
                ('pass_direction', models.CharField(blank=True, max_length=100, null=True)),
                ('look_direction', models.CharField(blank=True, max_length=100, null=True)),
                ('grazing_angle', models.CharField(blank=True, max_length=100, null=True)),
                ('azimuth_angle', models.CharField(blank=True, max_length=100, null=True)),
                ('doppler_cone_angle', models.CharField(blank=True, max_length=100, null=True)),
                ('file_format', models.CharField(blank=True, max_length=100, null=True)),
                ('name', models.CharField(max_length=100)),
                ('file_name', models.CharField(max_length=256)),
                ('country_code', models.CharField(blank=True, max_length=64, null=True)),
                ('collection_date', models.DateField(blank=True, null=True)),
                ('collection_start_time', models.CharField(blank=True, max_length=256, null=True)),
                ('corner_coords', models.CharField(max_length=255)),
                ('sensor', models.CharField(max_length=128)),
                ('target_name', models.CharField(blank=True, max_length=256, null=True)),
                ('file_size', models.IntegerField()),
                ('dzi_location', models.CharField(max_length=256)),
                ('kml_location', models.CharField(max_length=256)),
                ('kmz_location', models.CharField(max_length=256)),
                ('thumbnail_location', models.CharField(max_length=256)),
                ('resource_location', models.CharField(max_length=256)),
                ('processed', models.BooleanField(default=False)),
                ('created_at', models.DateField(auto_now_add=True)),
                ('updated_at', models.DateField(auto_now=True)),
                ('mpoly', django.contrib.gis.db.models.fields.PolygonField(srid=4326)),
            ],
        ),
    ]

This migration does not run, causing my 0022 migration to fail since the table is not put back. I am not sure why this does not run or if I need to do something more. I tried to force it with a:

python manage.py migrate swsite 0021_cesiumentity

and I just get this:

Operations to perform: Target specific migration: 0021_cesiumentity, from swsite Running migrations: No migrations to apply.

So I am not sure why this is happening or what I am missing?

I had issues with previous migrations saying things existed (which makes sense I am not working on my development but my test server), so I just faked those if that matters I am not sure.

Codejoy
  • 3,722
  • 13
  • 59
  • 99

2 Answers2

1

Perhaps you made a mistake when faking migrations.

What does python manage.py showmigrations output? If it shows 0021_cesiumentity as being applied, then running python manage.py migrate swsite 0021_cesiumentity will have no effect.

To re-run that migration, you would have to fake back to the migration before (0020), then rerun python manage.py migrate swsite 0021_cesiumentity.

Alasdair
  • 298,606
  • 55
  • 578
  • 516
  • how do i fake back to the migration before? I did do the show migrations and it does have a [X] on 0021_cresiumentity – Codejoy Mar 08 '17 at 15:55
  • If the migration has an `[x]` then either you have already run it or you faked it. The [duplicate question](http://stackoverflow.com/questions/31953587/rerun-a-data-migration-on-django-1-8) gives an example of how to re-run a migration by faking back to the previous one first. – Alasdair Mar 08 '17 at 16:52
  • Yep got it working and so I marked this as right thanks for the help! – Codejoy Mar 08 '17 at 16:53
0

Django migrations are tracked using the 'django_migrations' table in your database. This is how Django records what migrations have been applied and what hasn't. If you check in this table, it will show you the migration file names that have been run on the DB.

If you want to rerun a migration, you need to delete the row in the django_migrations table with the corresponding file name. Then migrate again.

zubhav
  • 1,519
  • 1
  • 13
  • 19