api_notebook.user_id field is shorter than the referenced field
vsemionov opened this issue · comments
auth_user.username is varchar(150)
api_notebook.user_id is varchar(30)
bin/populate.sh worked in the past with uuid usernames, but now it fails because uuid length is 36 and doesn't fit in user_id
I think the reason for this behavior is the undocumented swappable property of the User model. It is designed to be replaceable by custom models. However, the configured model must have its data in the initial migration of the app that defines the model. The migrations code seems to generate references to the initial migration of swappable models. I am using the default User model, and its initial migration sets the username to 30 chars. Hence my username FKs are 30 chars long. I am able to work around this with a RunSQL migration to alter the FK data type to varchar(15), but I am in doubt if it's the right thing to do.
It is left to explain how the populate script worked before. It is possible that it worked at a time when user child objects referred to users by id instead of username and joins were performed to handle user child requests.