Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Cannot correct a failed migration django

I inadvertently did this:

ordering = models.IntegerField(default="Order/position")

I ran makemigrations and got no error. When I ran migrate it blew up with the error:

ValueError: invalid literal for int() with base 10: 'Order/position'

what I had meant to do was this:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

ordering = models.IntegerField(default=0, verbose_name="Order/Position")

I updated to the correct field definition and while makemigrations is happy and noted the change migrate still keeps throwing that same error.

How do I fix this?

In case this matters – I am running Django with Postgres and both are in Docker containers

Is it possible to "cancel" a previously failed migration?
Is it common for makemigration to not catch big errors like this?

>Solution :

The best is probably to fix the migration file itself. In the migration file, it will probably looked like:

from django.db import migrations, models


class Migration(migrations.Migration):
    dependencies = [
        # …
    ]

    operations = [
        migrations.CreateModel(
            name='MyModel',
            fields=[
                (
                    'id',
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name='ID',
                    ),
                ),
                (
                    'ordering',
                    models.IntegerField(
                        default='Order/position',
                    ),
                ),
            ],
        )
    ]

You fix this by altering the definition for ordering to the IntegerField you described.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading