django 1.11没有检测到变化

时间:2018-05-23 11:48:34

标签: python django django-models

你好,我在django迁移中遇到了一个问题,我已经在" connection"中创建了一个模型类。应用程序的model.py但我的ubantu 14.04终端在运行" python manage.py makemigrations"没有检测到任何变化,我也在上面的命令中指定了应用程序名称,但确实没有。请帮帮我。谢谢 以下是我的迁移:

admin
 [X] 0001_initial
 [X] 0002_logentry_remove_auto_add
analytics
 (no migrations)
auth
 [X] 0001_initial
 [X] 0002_alter_permission_name_max_length
 [X] 0003_alter_user_email_max_length
 [X] 0004_alter_user_username_opts
 [X] 0005_alter_user_last_login_null
 [X] 0006_require_contenttypes_0002
 [X] 0007_alter_validators_add_error_messages
 [X] 0008_alter_user_username_max_length
connection
 [X] 0001_initial
contenttypes
 [X] 0001_initial
 [X] 0002_remove_content_type_name
reports
 (no migrations)
sessions
 [X] 0001_initial

还有其他需要请发表评论。

这是我想通过连接应用程序的model.py文件在db中添加的表。

class BModel(models.Model):
    user              = models.ForeignKey(User, related_name="reports_user")
    dataset           = models.ForeignKey(DatasetRecord, related_name="dataset_record")
    name              = models.CharField(max_length=100)
    created_date      = models.DateTimeField(default=timezone.now, blank=True, null=True)
    updated_date      = models.DateTimeField(default=timezone.now)

    def __unicode__(self):
        return '%s' % self.id

    class Meta:
        app_label = 'daas'

,这是model.py文件代码。

# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.utils import timezone
from django.db import models
from daas.models import *
# Create your models here.
#on_delete=models.DO_NOTHING,

class Dbconnection(models.Model):
    user = models.ForeignKey(User, related_name="db_user")
    hostname = models.CharField(max_length=50)
    port = models.CharField(max_length=10,default=3306)
    dbname = models.CharField(max_length=50)
    dbuser = models.CharField(max_length=50)
    dbpassword = models.CharField(max_length=50)
    connection_type = models.CharField(max_length=50)
    connection_name = models.CharField(max_length=50)


    def __unicode__(self):
        return '%s' % self.id

    class Meta:
        app_label = 'daas'


class DatasetRecord(models.Model):
    user = models.ForeignKey(User, related_name="dataset_user")
    dataset = models.CharField(max_length=50)
    sqlquery = models.TextField()
    connection = models.ForeignKey(Dbconnection, related_name="db_connection")
    created_date = models.DateTimeField(default=timezone.now, blank=True, null=True)
    updated_date = models.DateTimeField(default=timezone.now)

    def __unicode__(self):
        return '%s' % self.id

    class Meta:
        app_label = 'daas'


class Reports(models.Model):
    user              = models.ForeignKey(User, related_name="reports_user")
    dataset           = models.ForeignKey(DatasetRecord, related_name="dataset_record")
    row_dimension     = models.TextField()
    col_metrics       = models.TextField()
    report_type       = models.CharField(max_length=50)
    status            = models.CharField(max_length=50)
    report_name       = models.CharField(max_length=100)
    custom_data       = models.TextField()
    query_json      = models.TextField()
    created_date      = models.DateTimeField(default=timezone.now, blank=True, null=True)
    updated_date      = models.DateTimeField(default=timezone.now)

    def __unicode__(self):
        return '%s' % self.id

    class Meta:
        app_label = 'daas'



class CustomDashboard(models.Model):
    user              = models.ForeignKey(User, related_name="daas_userdashboard")
    dashboard_name    = models.TextField()
    created_date      = models.DateTimeField(default=timezone.now, blank=True, null=True)
    updated_date      = models.DateTimeField(default=timezone.now)

    def __unicode__(self):
        return '%s' % self.id

    class Meta:
        app_label = 'daas'




class CustomDashboardReport(models.Model):
    customdashboard   = models.ForeignKey(CustomDashboard, related_name="daas_customdashboardreport")
    report         = models.ForeignKey(Reports, related_name="Reports_daas_customdashboardreport")
    report_title      = models.TextField()
    custom_data      = models.TextField()
    created_date      = models.DateTimeField(default=timezone.now, blank=True, null=True)
    updated_date      = models.DateTimeField(default=timezone.now)
    class Meta:
        app_label = 'daas'

class Dashboard_Drill_Report(models.Model):
    user                  = models.ForeignKey(User, related_name="daas_dashboarddrillreport")
    customdashboard       = models.ForeignKey(CustomDashboard, related_name="daas_dashboarddrillreport")
    parent_report         = models.ForeignKey(Reports, related_name="parentreports_daas_dashboarddrillreport")
    child_report          = models.ForeignKey(Reports, related_name="childreports_daas_dashboarddrillreport")
    canvas_id             = models.TextField()
    created_date          = models.DateTimeField(default=timezone.now, blank=True, null=True)
    updated_date          = models.DateTimeField(default=timezone.now)
    class Meta:
        app_label = 'daas'



class SalesMetadata(models.Model):
    id = models.AutoField(primary_key=True)
    column_name = models.CharField(max_length=255)
    data_type = models.CharField(max_length=255, blank=True, null=True)
    identifier = models.CharField(max_length=45, blank=True, null=True)
    definition = models.CharField(max_length=255, blank=True, null=True)
    aggregation = models.CharField(max_length=50, blank=True, null=True)
    table_name = models.CharField(max_length=50, blank=True, null=True)
    type = models.CharField(max_length=45, blank=True, null=True)

    class Meta:

        managed = False
        db_table = 'sales_metadata'


class SalesMetadataDemo(models.Model):
    id = models.AutoField(primary_key=True)
    column_name = models.CharField(max_length=255)
    data_type = models.CharField(max_length=255, blank=True, null=True)
    identifier = models.CharField(max_length=45, blank=True, null=True)
    definition = models.CharField(max_length=255, blank=True, null=True)
    aggregation = models.CharField(max_length=50, blank=True, null=True)
    table_name = models.CharField(max_length=50, blank=True, null=True)
    type = models.CharField(max_length=45, blank=True, null=True)

    class Meta:

        managed = False
        db_table = 'sales_metadata_demo'

class FactOrderDemo(models.Model):
    business_date = models.IntegerField(db_column='Business_Date', blank=True, null=True)  # Field name made lowercase.
    product = models.CharField(db_column='Product', max_length=250, blank=True, null=True)  # Field name made lowercase.
    brand = models.CharField(db_column='Brand', max_length=50, blank=True, null=True)  # Field name made lowercase.
    category = models.CharField(db_column='Category', max_length=100, blank=True, null=True)
    channel = models.CharField(db_column='Channel', max_length=50, blank=True, null=True)  # Field name made lowercase.
    payment_method = models.CharField(db_column='Payment_Method', max_length=50, blank=True, null=True)  # Field name made lowercase.
    city = models.CharField(db_column='City', max_length=200, blank=True, null=True)  # Field name made lowercase.
    state = models.CharField(db_column='State', max_length=200, blank=True, null=True)  # Field name made lowercase.
    sales = models.DecimalField(db_column='Sales', max_digits=34, decimal_places=3, blank=True, null=True)  # Field name made lowercase.
    discount = models.DecimalField(db_column='Discount', max_digits=34, decimal_places=4, blank=True, null=True)  # Field name made lowercase.
    cancellations = models.DecimalField(db_column='Cancellations', max_digits=34, decimal_places=4)  # Field name made lowercase.
    total_orders = models.BigIntegerField(db_column='Total_Orders')  # Field name made lowercase.
    returns = models.CharField(db_column='Returns', max_length=200, blank=True, null=True)  # Field name made lowercase.

    class Meta:
        managed = False
        db_table = 'fact_order_demo'
        #unique_together = (('business_date', 'product', 'category', 'promotion', 'channel', 'payment_method', 'city', 'state', 'country'),)

请帮助我,我使用的是django 1.11版本的python verison 3.4.3

1 个答案:

答案 0 :(得分:0)

您需要将app_label更改为您在settings.py内installed_apps中添加的应用程序的名称

app_label ='连接'

参考:app_label django docs

“我仍然感到困惑的是,我所有的东西都在使用app_label ='daas'工作,并且还创建了其他表,但是为什么这次这次不起作用”的答案可能是“如果模型是在INSTALLED_APPS中的应用程序外部定义,则必须声明它属于哪个应用程序”,直到我看到实际的应用程序为止。