已解決:%22DO_NOTHING%22 未定義 django

貢獻.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 導入用戶

如果您使用的是第三方身份驗證庫,您可能還需要添加其導入。

相關文章:

發表評論