贡献.auth
Django 中没有为 %22DO_NOTHING%22 过滤器定义的行为。 如果在模板或视图中使用,这可能会导致意外结果。
.db.utils.ProgrammingError: %22DO_NOTHING%22 is not defined I'm trying to run a migration in Django, but I get the following error: <code>django.db.utils.ProgrammingError: %22DO_NOTHING%22 is not defined</code> The migration file looks like this: <code># -*- coding: utf-8 -*- # Generated by Django 1.11 on 2017-08-18 13:16 from __future__ import unicode_literals from django.db import migrations, models class Migration(migrations.Migration): dependencies = [("myapp", "0004_auto_20170818_1255")] operations = [migrations.AlterField(model_name="mymodel", name="field1", field=models.ForeignKey(null=True, on_delete=models.DO_NOTHING, related_name="+", to="myapp"))] # noqa</code> The model it's referring to looks like this (the field in question is <code>field1</code>) : <code>class MyModel(models.Model): field1 = models.... # other fields here</code> # noqa
错误是说 DO_NOTHING
option is not defined – 这可能是因为您使用的 Django 版本不支持它。 要解决这个问题,您可以将 Django 更新到更新的版本,或者更改 on_delete
选择其他受支持的东西。
解决Django 'Handler' is not defined
此错误是由于 Django 项目中缺少 import 语句引起的。 您可以通过将以下行添加到项目的导入部分来解决此问题:
从 django.contrib.auth.models 导入用户
如果您使用的是第三方身份验证库,您可能还需要添加其导入。