django 1.11 изменений не обнаружено - PullRequest
0 голосов
/ 23 мая 2018

Здравствуйте, я застрял в точке миграции 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приложение.

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'),)

Пожалуйста, помогите мне, я использую python verison 3.4.3 с версией django 1.11

1 Ответ

0 голосов
/ 05 марта 2019

Вам нужно изменить app_label на имя приложения, которое вы добавили в установленные_apps внутри settings.py

app_label = 'connection'

Ссылка: app_label django docs

И ответ на вопрос "но я все еще в замешательстве, что у меня все работало, файл с app_label = 'daas' и создал другие таблицы, но почему на этот раз это не работает", может быть,this «Если модель определена вне приложения в INSTALLED_APPS, она должна объявить, к какому приложению она принадлежит», не уверен, пока не увижу реальные приложения.

...