Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python “Django”;名称错误:名称';专辑';“未定义”;_Python_Django_Database_Model View Controller_Model - Fatal编程技术网

Python “Django”;名称错误:名称';专辑';“未定义”;

Python “Django”;名称错误:名称';专辑';“未定义”;,python,django,database,model-view-controller,model,Python,Django,Database,Model View Controller,Model,我试图运行see并操作一个简单的django数据库,但是djangoshell的错误是我的一个模型没有定义 大多数与我类似的错误问题都是由于人们在声明模型之前引用了它。但是,我没有引用相册中的任何其他型号 models.py from __future__ import unicode_literals from django.db import models class Album(models.Model): artist = models.CharField(max_leng

我试图运行see并操作一个简单的django数据库,但是djangoshell的错误是我的一个模型没有定义

大多数与我类似的错误问题都是由于人们在声明模型之前引用了它。但是,我没有引用相册中的任何其他型号

models.py

from __future__ import unicode_literals

from django.db import models


class Album(models.Model):
    artist = models.CharField(max_length=250)
    title = models.CharField(max_length=500)
    genre = models.CharField(max_length=100)
    logo = models.CharField(max_length=1000)


class Song(models.Model):
    album = models.ForeignKey(Album, on_delete=models.CASCADE)
    file_type = models.CharField(max_length=10)
    title = models.CharField(max_length=250)
我得到的错误是:

你知道这个错误的原因是什么吗


作为参考,我将遵循Newboston的django教程。

当您打开shell时,它只是一个python shell,没有导入应用程序中的任何内容

您应该首先导入模型:

from your_app_name.models import Album
如果您不想每次导入模型,请使用将为您加载模型的。使用
shell\u plus
命令:

python manage.py shell_plus

希望它对你有所帮助

当你打开你的shell时,它只是一个python shell,没有从你的应用中导入任何东西

您应该首先导入模型:

from your_app_name.models import Album
如果您不想每次导入模型,请使用将为您加载模型的。使用
shell\u plus
命令:

python manage.py shell_plus
希望它有帮助

你应该这样尝试--

你应该这样试试--


你也可以用引号写相册,如下所示

album = models.ForeignKey("Album", on_delete=models.CASCADE)

这对我有用

你也可以用引号写相册,如下所示

album = models.ForeignKey("Album", on_delete=models.CASCADE)

这对我有用

很晚才回复,但感谢您的回复。我安装了django扩展,并将其添加到已安装的应用程序中,现在可以让它工作了。回复很晚,但感谢您的回复。我安装了django扩展,并将其添加到已安装的应用程序中,现在可以让它工作了。