Django不会迁移应用

时间:2017-06-06 10:10:55

标签: python django postgresql

我正在研究一个用于学习目的的django项目。我已经创建了一个应用organization并安装了它。当我运行python manage.py makemigrations organization时,它可以正常显示更改。

Migrations for 'organization':
  organization/migrations/0001_initial.py:
    - Create model Organization
    - Create model Principle

但是当我运行python manage.py migrate organization时,它不会迁移并且不会显示任何要应用的更改。

Operations to perform:
  Apply all migrations: organization
Running migrations:
  No migrations to apply.

我正在使用postgresql并在删除所有drop owned by user_name;文件夹后尝试migrations。但仍然行不通。它每次都表明同样的事情。如何解决这个问题?

环境:
操作系统版本Ubuntu 16.04
Django版本1.10.3
PostgreSQL版本9.5.7

organization / models.py

from django.db import models
from django.contrib.postgres.fields import JSONField    

class Principle(models.Model):
    name = models.CharField(max_length=256)
    description = models.CharField(max_length=256)
    contact_no = models.CharField(max_length=256)
    status = models.BooleanField()


class Organization(models.Model):
    name = models.CharField(max_length=256)
    liceneses = [
        ('pvt','Private Limited',),
        ('pub','Public Limited',),
        ('part','Partnership',),
        ('prop','proprietary',)
    ]

    licenese_type = models.CharField(max_length=10, choices=liceneses)
    key_person_name = models.CharField(max_length=256)
    key_person_position = models.CharField(max_length=256)
    key_person_contact_no = models.CharField(max_length=45)
    primary_organization_contact = models.CharField(max_length=45)
    organization_address = models.TextField()
    additional_info = JSONField()
    date_of_registration = models.CharField(max_length=45)
    status = models.BooleanField()

1 个答案:

答案 0 :(得分:6)

在这些情况下,从所有应用程序的__init__.py文件中删除迁移文件夹中的所有迁移文件,确保已在已安装的应用程序中安装该应用程序

然后删除数据库表,

run python manage.py migrate
run python manage.py makemigrations
run python manage.py migrate