“cannot be cast to type integer” error

后端 未结 2 606
太阳男子
太阳男子 2020-12-31 15:52

This is my first question so I will appreciate patience.

I changed a few attributes to IntegerField from CharField. Listed below is the code:

rating         


        
相关标签:
2条回答
  • 2020-12-31 16:38

    You need to add "USING (col_name::integer)" to eliminate this error. But in that case you have to use direct query.

    migrateEngine.execute('ALTER TABLE test ALTER COLUMN testScore TYPE INTEGER USING testScore::integer')

    0 讨论(0)
  • 2020-12-31 16:46

    if you are happy to throw away your data, you can delete the column and create a new one

    if you want to keep your data, you need to either

    a) give your new column a different name, or
    b) create a temporary column to hold the data during the transition

    you then need a sequence of migrations

    1. a schema migration to add the new (or temp) column
    2. a data migration that explicitly moves the data, doing any required conversion (e.g. "A" -> 1)
    3. possibly a schema migration deleting your temporary column
    0 讨论(0)
提交回复
热议问题