Opened 9 years ago
Closed 9 years ago
#25913 closed Bug (needsinfo)
--fake-initial not working with apps with other table names
Reported by: | James Lin | Owned by: | nobody |
---|---|---|---|
Component: | Migrations | Version: | 1.8 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
I have the following migration step in "clients" app, notice the table name is "auth_client":
migrations.CreateModel( name='Client', fields=[ ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), ('created_at', models.DateTimeField(auto_now_add=True, verbose_name='date created', db_index=True)), ('updated_at', models.DateTimeField(auto_now=True, verbose_name='date modified', db_index=True)), ('logo', models.FileField(null=True, upload_to=goconnect_client.clients.models.logo_path, blank=True)), ('name', models.CharField(max_length=255, blank=True)), ('client_id', models.CharField(default=goconnect_client.clients.generators.generate_client_id, unique=True, max_length=100, db_index=True)), ('client_secret', models.CharField(default=goconnect_client.clients.generators.generate_client_secret, max_length=255, db_index=True, blank=True)), ('client_type', models.CharField(max_length=32, choices=[('confidential', 'Confidential'), ('public', 'Public')])), ('authorization_grant_type', models.CharField(max_length=32, choices=[('authorization-code', 'Authorization code'), ('implicit', 'Implicit'), ('password', 'Resource owner password-based'), ('client-credentials', 'Client credentials')])), ('skip_authorization', models.BooleanField(default=False)), ('redirect_uris', models.TextField(blank=True, validators=[goconnect_client.clients.validators.validate_uris])), ('cors', models.TextField(null=True, blank=True)), ('user', models.ForeignKey(related_name='clients_client', to=settings.AUTH_USER_MODEL)), ], options={ 'abstract': False, 'db_table': 'auth_client', 'swappable': 'AUTH_CLIENT_MODEL', }, bases=(grabone_models.misc.timestampedmixin.TimeStampedMixin, models.Model), ),
When I run:
./manage migrate clients --fake-initial
it complains about 'auth_client' table already exists.
"When migrate is run with the --fake-initial option, these initial migrations are treated specially. For an initial migration that creates one or more tables (CreateModel operation), Django checks that all of those tables already exist in the database and fake-applies the migration if so. Similarly, for an initial migration that adds one or more fields (AddField operation), Django checks that all of the respective columns already exist in the database and fake-applies the migration if so. Without --fake-initial, initial migrations are treated no differently from any other migration."
I am speculating that when determining the existence of the table it's using the default 'app_table' convention, and surely 'clients_client' table doesn't exist, but when running actual migration it uses 'auth_client' as table name and encounter the error.
Change History (2)
comment:1 by , 9 years ago
Summary: | --fake-migration not working with apps with other table names → --fake-initial not working with apps with other table names |
---|
comment:2 by , 9 years ago
Resolution: | → needsinfo |
---|---|
Status: | new → closed |
Type: | Uncategorized → Bug |
Could you please provide a
models.py
to reproduce the problem?