Django成功迁移但未在MYSQL上创建表

时间:2020-02-05 16:19:45

标签: python mysql django database-migration

有人可以帮我吗?

起初,我为我的APP创建了一个sqlite数据库,但现在需要将其迁移到MYSQL中。

在SQLITE中,一切正常,但是当我迁移到MYSQL时,并没有创建表。

在此先感谢您的帮助。


models.py

from django.db import models

class sslDomain(models.Model):
    domain = models.CharField(max_length=20, default='')
    expiration = models.TextField(max_length=50, default='')
    date_now = models.TextField(max_length=50, default='')
    status = models.IntegerField(max_length=50, default=0)
    daysleft = models.TextField(max_length=50, default='')

    def __str__(self):
        return self.domain

class logsTable(models.Model):
    logs_field = models.TextField(max_length=100, default='')

    def ___str__(self):
        return self.id

auth_db.py(我的DBrouter)

from .apps import *

class AuthSslDB:
    """
    A router to control all database operations on models in the
    auth application.
    """
    def db_for_read(self, model, **hints):
        """
        Attempts to read auth models go to auth_db.
        """
        if model._meta.app_label == SsldomainsConfig.name:
            return 'argus_v2_db'
        return None

    def db_for_write(self, model, **hints):
        """
        Attempts to write auth models go to auth_db.
        """
        if model._meta.app_label == SsldomainsConfig.name:
            return 'argus_v2_db'
        return None

    def allow_relation(self, obj1, obj2, **hints):
        """
        Allow relations if a model in the auth app is involved.
        """
        if obj1._meta.app_label == SsldomainsConfig.name or \
           obj2._meta.app_label == SsldomainsConfig.name:
           return True
        return None

    def allow_migrate(self, db, app_label, model_name=None, **hints):
        """
        Make sure the auth app only appears in the 'auth_db'
        database.
        """
        if app_label == SsldomainsConfig:
            return db == 'argus_v2_db'
        return None

settings.py

'argus_v2_db': {
    'ENGINE': 'django.db.backends.mysql',
    'NAME': 'argus_v2',
    'USER': 'yrollrei',
    'PASSWORD': '****',
    'HOST': '*.*.*.*',
    'PORT': '*',
}

DATABASE_ROUTERS = ['SSLDOMAINS.auth_db.AuthSslDB']

1 个答案:

答案 0 :(得分:0)

我刚刚注意到,如果我创建的新表不是来自sqlite,那它就可以了。

我的问题得以解决,只需将我的类克隆到models.py中,然后将其重命名即可。

希望它对有相同问题的其他人有用。