Renaming sequences

15 views
Skip to first unread message

Mike Dewhirst

unread,
Dec 18, 2019, 1:27:56 AM12/18/19
to Django users
Are there any consequences for renaming sequences to match the tables
which own them?

In an existing production Django project I have just converted auth.user
into common.user and company.userprofile into common.userprofile.

Having gone through the migration process more or less unscathed the
original sequences are owned by the renamed tables. Eg
public.auth_user_id_seq is owned by public.common_user.id

Everything seems to work fine but my unit tests are playing up and error
messages are showing the original (and still correct) sequence names. It
would make much visual sense to me now and especially to the future me
(or anyone else) if the sequences were renamed as well.

I know how I could do it but I just need to know if I should.

Thanks for any advice

Mike

Michael MacIntosh

unread,
Dec 18, 2019, 2:59:12 PM12/18/19
to django...@googlegroups.com
Hey Mike,

I'm not sure about your specific setup, but I assume you are using the
django.contrib.auth user model and are moving it over to your own app,
and you have your own userprofile model that links to it.  The user
model in django.contrib.auth is a swappable model.  Basically meaning as
long as it inherits from a base class (I believe BaseUser) and you
configure your settings (AUTH_USER_MODEL) to look at it, you should be
fine, as long as you get the user model via get_user_model.

A link to the documentation on this
https://docs.djangoproject.com/en/3.0/topics/auth/customizing/#referencing-the-user-model

The next section also goes into defining a custom user model.

But in short there should be no ill-effects if you do everything right 😉.

Also if you are moving your own user model into your own app, I would
recommend naming it something other than common, something containing
auth, like "catapp_auth" so it is clear that your user models and any
custom authorization / authentication happens in there.

Hope that helps!

Cheers,
Michael.

DANIEL URBANO DE LA RUA

unread,
Dec 18, 2019, 3:08:26 PM12/18/19
to Django users
Why you did taht on production and not to try before recreate the db in other place

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/386eb4f4-6229-331f-05a5-c47d168db1fd%40linear-systems.com.

Mike Dewhirst

unread,
Dec 18, 2019, 5:03:01 PM12/18/19
to django...@googlegroups.com
I haven't touched production yet. Things seem ok in dev but I'm still asking around due to under-confidence. And it will be fully tested in staging before deploying live.

Mike Dewhirst

unread,
Dec 18, 2019, 5:04:52 PM12/18/19
to django...@googlegroups.com
Thanks Michael. It has been interesting so far and I'm looking forward to understanding what I've done😄





-------- Original message --------
From: Michael MacIntosh <mmaci...@linear-systems.com>
Date: 19/12/19 06:58 (GMT+10:00)
Subject: Re: Renaming sequences

Reply all
Reply to author
Forward
0 new messages