PyCharm + Django ImportError:无法从python控制台中的模型导入新创建的类

时间:2017-12-04 19:28:03

标签: python django django-models pycharm

我正在构建Django网站(Django 1.11.2和Python 3.5.2),我遇到了问题

File "<input>", line 1, in <module>
ImportError: cannot import name 'Test'

执行命令from events.models import Test

events of events.models

# coding=utf-8
from __future__ import unicode_literals
from http.client import HTTPSConnection
from datetime import timedelta
from django.conf import settings
from django.contrib.auth import get_user_model
import json
from django.utils.safestring import mark_safe
from django.db import models
from django.urls import reverse
from django.utils.timezone import now

from django_cron import CronJobBase, Schedule

from django.db.models import Max


class EventClass(models.Model):
    game_class = models.CharField(max_length=100)
    game_name = models.CharField(max_length=100)

    tournament_name = models.CharField(max_length=100)
    tournament_round = models.CharField(max_length=100)
    tournament_type = models.CharField(max_length=100)



class Event(models.Model):

    game_class = models.CharField(max_length=100)

........................................
........................................

class Test(models.Model):
    test = models.CharField(max_length=100)

如何在没有任何错误的情况下导入?

P.S。

from events.models import Event 

正常工作

甚至尝试过

class EventClass2(models.Model):
    game_class = models.CharField(max_length=100)
    game_name = models.CharField(max_length=100)

    tournament_name = models.CharField(max_length=100)
    tournament_round = models.CharField(max_length=100)
    tournament_type = models.CharField(max_length=100)

makemigration events
migrate events

from events.models import EventClass2

再次出现同样的错误

Traceback (most recent call last):
  File "<input>", line 1, in <module>
ImportError: cannot import name 'EventClass2'

0 个答案:

没有答案