[英]How to disable migrations for specific Django 1.7 apps?
How do you disable migrations for specific apps in Django>=1.7? 如何在Django> = 1.7中禁用特定应用程序的迁移?
I'm trying to upgrade from Django 1.6 to 1.7, and I made some trivial changes to Django's auth app to change labels, but a design flaw in Django>=1.7 now treats all attributes as part of the database schema, triggering a new migration. 我正在尝试从Django 1.6升级到1.7,并且对Django的auth应用做了一些微不足道的更改以更改标签,但是Django> = 1.7中的设计缺陷现在将所有属性视为数据库架构的一部分,从而触发了新的迁移。 Moreover, running manage.py makemigration myapp
generates a migration for all other apps touching myapp
, so even though I'm not explicitly trying to create a migration for auth
, it's forcing me to do so, and I see no way to turn this off. 而且,运行manage.py makemigration myapp
为所有其他接触myapp
应用程序生成迁移,因此,即使我没有明确尝试为auth
创建迁移,这也迫使我这样做,而且我看不到有办法将其关闭。
This is creating havoc, since I have a dozen apps that touch auth
, so this is causing Django to create over a dozen pointless migrations. 由于我有十几个触摸auth
应用程序,因此这造成了严重破坏,因此这导致Django创建了十几个毫无意义的迁移。
I tried creating a custom auth
migration directory using MIGRATION_MODULES
, but doesn't seem to work. 我尝试使用MIGRATION_MODULES
创建自定义auth
迁移目录,但似乎不起作用。 Any app that relies on auth now throws an error like: 现在,任何依赖身份验证的应用程序都将引发如下错误:
ValueError: Lookup failed for model referenced by field helpdesk.Queue.group: auth.Group
If I try to migrate auth
. 如果我尝试迁移auth
。 How do I fix this? 我该如何解决? Ideally, the simplest solution would be to just "turn off" migrations for auth
, since I'm not actually making any changes to it. 理想情况下,最简单的解决方案是仅“关闭” auth
迁移,因为我实际上并未对其进行任何更改。
Edit: This is the custom migration Django forces me to generate: 编辑:这是Django强迫我生成的自定义迁移:
class Migration(migrations.Migration):
dependencies = [
('admin', '0001_initial'),
('auth', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='LogEntry',
fields=[
],
options={
'ordering': ('-action_time',),
'verbose_name': 'log entry',
'proxy': True,
'verbose_name_plural': 'log entries',
},
bases=('admin.logentry',),
),
migrations.AlterField(
model_name='permission',
name='name',
field=models.CharField(max_length=500, verbose_name='name'),
preserve_default=True,
),
migrations.AlterField(
model_name='user',
name='username',
field=models.CharField(help_text='Required. 30 characters or fewer. Letters, digits and @/./+/-/_ only.', unique=True, max_length=75, verbose_name='username', validators=[django.core.validators.RegexValidator('^[\\w.@+-]+$', 'Enter a valid username.', 'invalid')]),
preserve_default=True,
),
]
My custom changes are to make the username and email fields the same length (because the two are the same in my system), as well as change the default validator to validate them both as an email address. 我的自定义更改是使用户名和电子邮件字段的长度相同(因为两者在我的系统中相同),并更改默认验证程序以将它们均作为电子邮件地址进行验证。 I've been using these changes since Django 1.3. 自Django 1.3起,我一直在使用这些更改。 Presumably, they're only a problem now that I'm no longer using South and have to re-generate all my migrations. 大概,这只是一个问题,因为我不再使用South,而必须重新生成我的所有迁移。
And it looks like I can't use MIGRATION_MODULES
to even generate this into a custom migration folder, because I have some other apps that depend on auth's 0001_initial migration, like: 看来我什至无法使用MIGRATION_MODULES
将其生成到自定义迁移文件夹中,因为我还有一些依赖于auth的0001_initial迁移的其他应用,例如:
class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
So if I override it with MIGRATION_MODULES
like: 因此,如果我用MIGRATION_MODULES
覆盖它,例如:
MIGRATION_MODULES = {
'auth': 'myoverrides.auth_migrations',
}
that migration effectively disappears, throwing the error. 迁移有效消失,引发错误。
It's a bit of a hack, but I modified my settings.py
to check sys.argv
for "makemigrations" and remove the conflicting apps, that are effectively unmanaged, from my INSTALLED_APPS
list. 有点黑客,但我修改了我的settings.py
以检查sys.argv
中的“ makemigrations”,并从我的INSTALLED_APPS
列表中删除了实际上不受管理的冲突应用程序。 This allowed me to properly generate a custom auth
migration. 这使我能够正确生成自定义auth
迁移。 eg 例如
if 'makemigrations' in sys.argv
INSTALLED_APPS.remove('conflicting_third_party_app')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.