I'm having issues with third-party packages in Django that has relations with the user model. I've swapped out the user model to a legacy table `users`. After running migrations and syncdb I couldn't save objects in the third-party packages' models because of a foreign key error:
```
(1452, 'Cannot add or update a child row: a foreign key constraint fails (`mcr`.`oauth2_client`, CONSTRAINT `user_id_refs_id_caad7e47` FOREIGN KEY (`user_id`) REFERENCES `user_user` (`id`))')
```
I checked the foreign keys relating to the user model and saw that instead of pointing to `users` the ones in the third-party packages are relating to `user_user` (which would be the default name of the table if wouldn't have specified `db_name = 'users'`).
So I dug further and found this in django-oauth2-provider's (and equivalent in django-tastypie's) South migrations:
```python
db.create_table('oauth2_client', (
('id',
self.gf('django.db.models.fields.AutoField')(primary_key=True)),
('user',
self.gf('django.db.models.fields.related.ForeignKey')(to=orm[user_model_label])),
('url',
self.gf('django.db.models.fields.URLField')(max_length=200)),
('redirect_uri',
self.gf('django.db.models.fields.URLField')(max_length=200)),
('client_id',
self.gf('django.db.models.fields.CharField')(default='37b581bdc702c732aa65', max_length=255)),
('client_secret',
self.gf('django.db.models.fields.CharField')(default='5cf90561f7566aa81457f8a32187dcb8147c7b73', max_length=255)),
('client_type',
self.gf('django.db.models.fields.IntegerField')()),
))
db.send_create_signal('oauth2', ['Client'])
```
`user_model_label` is set from `django.conf.settings.AUTH_USER_MODEL`, so should be the correct label (printed it and it's the correct string).
The tables are created correctly but it seems like the foreign keys are messed up somewhere along the way, my initial feeling is that South incorrectly assumes the default name for the table when creating foreign keys.