Migrating from 'djangae.contrib.gauth.sql' to 'djangae.contrib.gauth_sql'

5 views
Skip to first unread message

Luis Larco

unread,
Mar 20, 2019, 7:49:43 PM3/20/19
to djangae-users
Hi,

I'm working on upgrading the installed apps/dependencies of a djangae project that I haven't touched in about 2 years, where I have upgraded django>=1.8,<1.9 to django>=1.11.19,<2.0.

Throughout this upgrade, I have replaced the installed app 'djangae.contrib.gauth.sql' to 'djangae.contrib.gauth_sql'. In the settings.py file, I had the AUTH_USER_MODEL set to 'djangae.GaeUser', and my SQL database currently contains the tables djangae_gaeuser, djangae_gaeuser_groups, and djangae_gaeuser_user_permissions.

Without updating the value of AUTH_USER_MODEL, I get the following error:

"AUTH_USER_MODEL refers to model '%s' that has not been installed" % settings.AUTH_USER_MODEL
django
.core.exceptions.ImproperlyConfigured: AUTH_USER_MODEL refers to model 'djangae.GaeUser' that has not been installed

I then switched the value to 'gauth_sql.GaeUser', and the server starts. However, whenever I open a view that queries the database, I get the following error:

ProgrammingError: (1146, "Table 'my_app.gauth_sql_gaeuser' doesn't exist")

I then created a new model in models.py called GaeUser:

class GaeUser(djangae.contrib.gauth_sql.models.GaeAbstractUser):
   
class Meta:
        db_table
= 'djangae_gaeuser'

and updated the value of AUTH_USER_MODEL to 'my_app.GaeUser'. When running the server and opening a view that queries the database, I get the following error:

OperationalError: (1054, "Unknown column 'djangae_gaeuser.email_lower' in 'field list'")

I was looking at https://code.djangoproject.com/ticket/25313, but it seems that the solution suggested in there applies to migrating from auth.User to a custom User class, rather than migrating from djangae.GaeUser to a a custom User class that extends djangae.contrib.gauth_sql.models.GaeAbstractUser.

I feel like I'm getting close to fixing this issue, but I'm not quite sure if I will be required to perform some sort of migration and/or restructuring the SQL database to reflect the correct naming for the user database.

Any advice would be appreciated!

Thanks

Adam Alton

unread,
Mar 25, 2019, 7:22:33 AM3/25/19
to Luis Larco, djangae-users
Hey,

Yes, it looks like we somehow haven't accounted for this upgrade path, and so haven't made life easy for you!

All the steps you've done look sensible though, and I think you're right in saying that your next step is that you're going to need to create a migration to add the `email_lower` field.

Given that the existing migration in the gauth_sql app already has that field on the model, I think you might be best off just creating a raw SQL statement to add the column to the table.  Because if you create a migration that adds the field to the model you'll probably find that Django ignores it or gets confused because it thinks that the field already exists on the model.  So just issuing something along the lines of `ALTER TABLE djangae_gaeuser ADD COLUMN email_lower VARCHAR(254) NULL UNIQUE` should hopefully do the trick.  But don't assume that my SQL is correct!  Use at your own risk 😀.

You then obviously have the problem of needing to populate that column, which will require some more SQL fun in order to copy the values from the `email` column to the `email_lower` column (and lower-case them).  Shouldn't be hard, unless you've got some duplicate email addresses in there, in which case it will be a little bit more "fun"!

I hope that helps.  Let us know how you get on.

Adam

--
You received this message because you are subscribed to the Google Groups "djangae-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to djangae-user...@googlegroups.com.
To post to this group, send email to djanga...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/djangae-users/713f9706-5bc6-4160-a753-ad0094c7a980%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages