fflush_life
fflush_life

Reputation: 43

Django - Invalid literal for int() with base 10 python django

I added new ForeignKey in models with default = 't' and Django said

Django - Invalid literal for int() with base 10 't'

when I made migrations. Than I deleted that row but I still can't migrate because of this error.

Upvotes: 1

Views: 968

Answers (1)

Selcuk
Selcuk

Reputation: 59184

If the primary key of the related model is an int (ids are int by default), the ForeignKey column is also an int.

What you can do now is to edit the generated migration file (yourapp/migrations/000x_auto_xyz.py) and delete the part that tries to set the default value. For example, if your migration file looks like this:

class Migration(migrations.Migration):

    dependencies = [
    ...
    ]

    operations = [
        migrations.CreateModel(
            name='Application',
            fields=[
                ...
                ('myforeignkey', models.ForeignKey(to='otherapp.OtherModel', default='t')),
            ],
            ...
    ]

then just remove the , default='t' part and re-run manage.py migrate.

Upvotes: 2

Related Questions