[Fixed]-Python 2 -> 3 Django migration causes field parameter type change

12๐Ÿ‘

โœ…

I came across a Django ticket after asking this question, where the recommendation from a Django developer is to edit any legacy migrations files (such as 0001_initial) that contain (Python 3) bytes literals, removing the b and making them string-literals in Python 3.

Editing migrations to fix this issue is safe.

From there you should presumably be able to delete the migrations modules that were made with python3 ./manage.py makemigrations, and redo that command, which should no longer take issue with the type of that argument.

I used the following to do a mass-find-and-replace of all instances of 'db_column=b' with 'db_column='. Granted, you should absolutely check git diff before making that commit.

grep -nrl "db_column=b" apps | xargs sed -i "s/db_column=b/db_column=/g"
๐Ÿ‘คBrad Solomon

Leave a comment