为什么Django迁移不迁移表?

时间:2020-05-03 07:45:36

标签: django django-models django-migrations

我的django迁移无法正常工作。在这三个模型中,我在应用程序的初始版本中更改了一个模型(表),并运行makemigrations,然后运行migration命令,但是该特定表的迁移未正确进行,因此我认为该应用程序存在问题。我从数据库中删除了该表,还创建了一个新应用程序,并将所有代码从第一个应用程序复制到该应用程序(包括模型,视图等中的代码)。但是,当我使用迁移命令时,我仍然看不到数据库中的表。

模型代码如下

class Questions(models.Model):
questionid = models.AutoField(primary_key=True)
questiontitle = models.CharField(max_length=50, default = "Title awaited")
questiontxt = models.TextField(max_length=1000)
ans1 = models.CharField(max_length=150)
ans2 = models.CharField(max_length=150)
ans3 = models.CharField(max_length=150)
qcreate_date = models.DateTimeField(default =timezone.now())
is_published = models.BooleanField(default = True)
published_date = models.DateTimeField(default = datetime.now(), blank = True)


def _str_(self):
    return self.questiontitle

def get_absolute_url(self):
    return reverse('Question List')


class Answers(models.Model):
userid = models.Integerfield()
questionid = models.IntegerField
userid = models.IntegerField
ans1 = models.CharField(max_length=150, blank = True)
ans2 = models.CharField(max_length=150, blank = True)
ans3 = models.CharField(max_length=150, blank = True)
anspublished_date = models.DateTimeField(default=timezone.now())

The messages I get upon running 
 python manage.py makemigrations 
 python manage.py migrate

I am posting the relevant error message

Migrations for 'qanda':
qanda\migrations\0005_auto_20200503_1342.py
- Alter field anspublished_date on answers
- Alter field published_date on questions
- Alter field qcreate_date on questions 

  Operations to perform:
  Apply all migrations: admin, auth, contenttypes, qanda, sessions
  Running migrations:
  Applying qanda.0003_auto_20200503_1331...Traceback (most recent call last):
  File "C:\Users\admin67\Anaconda3\envs\django2\lib\site- 
  packages\django\db\backends\utils.py", line 86, in _execute
  return self.cursor.execute(sql, params)
  psycopg2.errors.UndefinedTable: relation "qanda_answers" does not exist

  django.db.utils.ProgrammingError: relation "qanda_answers" does not exist

0 个答案:

没有答案