psycopg2.DataError: invalid input syntax for integer: “test” Getting error when moving code to test server

后端 未结 2 671
我在风中等你
我在风中等你 2021-02-15 02:57

I\'m running Django 1.11 with Python 3.4 on Ubuntu 14.04.5

Moving my development code to the test server and running into some strange errors. Can anyone see what is wr

2条回答
  •  甜味超标
    2021-02-15 03:42

    The issue is likely related to this open bug in Django. You have some test data in one of the fields that you are now converting to a ForeignKey.

    For instance, maybe department used to be a CharField and you added an employee who has "test" as their department value. Now you're trying to change department from a CharField to a ForeignKey. The issue is that Django is trying to convert the previous value "test" into a relational value (integer) for the ForeignKey.

    I can think of a few good solutions:

    • If this is just a test database, just reset your database and run the migration on a clean database
    • If you need to migrate the existing data, figure out what field has the "test" value. Then try something similar to the solution given in the bug report:

    ```

    from __future__ import unicode_literals
    
    from django.db import migrations
    
    class Migration(migrations.Migration):
        dependencies = [
            ('documents', '0042_auto_19700101-0000'),
        ]
    
        operations = [
            migrations.RunSQL('ALTER TABLE documents_document_tags ALTER tag_id TYPE varchar(32);'),
        ]
    

提交回复
热议问题