djangoとmysqlのカスタムバックグラウンド管理システム


djangoプロジェクトを作成したら、コンポーネントmanageを作成します.
インストールpymysql,pip install pymysql
ファイルを変更しますinit__.py
import pymysql 

pymysql.install_as_MySQLdb()


settingが見つかりました.py、設定の変更
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'testchar',
        'USER': 'root',
        'PASSWORD': '',
        'HOST': 'localhost',
        'PORT': '3306',
    }
}

既存のmysqlデータベースからmodelsを取得するには、コマンドを使用します.
 manage.py inspectdb
  

class AuthGroup(models.Model):
    name = models.CharField(unique=True, max_length=80)

    class Meta:
        managed = False
        db_table = 'auth_group'


class AuthGroupPermissions(models.Model):
    group_id = models.IntegerField()
    permission_id = models.IntegerField()

    class Meta:
        managed = False
        db_table = 'auth_group_permissions'
        unique_together = (('group_id', 'permission_id'),)


class AuthPermission(models.Model):
    name = models.CharField(max_length=255)
    content_type_id = models.IntegerField()
    codename = models.CharField(max_length=100)

    class Meta:
        managed = False
        db_table = 'auth_permission'
        unique_together = (('content_type_id', 'codename'),)


class AuthUser(models.Model):
    password = models.CharField(max_length=128)
    last_login = models.DateTimeField(blank=True, null=True)
    is_superuser = models.IntegerField()
    username = models.CharField(unique=True, max_length=150)
    first_name = models.CharField(max_length=30)
    last_name = models.CharField(max_length=150)
    email = models.CharField(max_length=254)
    is_staff = models.IntegerField()
    is_active = models.IntegerField()
    date_joined = models.DateTimeField()

    class Meta:
        managed = False
        db_table = 'auth_user'


class AuthUserGroups(models.Model):
    user_id = models.IntegerField()
    group_id = models.IntegerField()

    class Meta:
        managed = False
        db_table = 'auth_user_groups'
        unique_together = (('user_id', 'group_id'),)


class AuthUserUserPermissions(models.Model):
    user_id = models.IntegerField()
    permission_id = models.IntegerField()

    class Meta:
        managed = False
        db_table = 'auth_user_user_permissions'
        unique_together = (('user_id', 'permission_id'),)


class DjangoAdminLog(models.Model):
    action_time = models.DateTimeField()
    object_id = models.TextField(blank=True, null=True)
    object_repr = models.CharField(max_length=200)
    action_flag = models.PositiveSmallIntegerField()
    change_message = models.TextField()
    content_type_id = models.IntegerField(blank=True, null=True)
    user_id = models.IntegerField()

    class Meta:
        managed = False
        db_table = 'django_admin_log'


class DjangoContentType(models.Model):
    app_label = models.CharField(max_length=100)
    model = models.CharField(max_length=100)

    class Meta:
        managed = False
        db_table = 'django_content_type'
        unique_together = (('app_label', 'model'),)


class DjangoMigrations(models.Model):
    app = models.CharField(max_length=255)
    name = models.CharField(max_length=255)
    applied = models.DateTimeField()

    class Meta:
        managed = False
        db_table = 'django_migrations'


class DjangoSession(models.Model):
    session_key = models.CharField(primary_key=True, max_length=40)
    session_data = models.TextField()
    expire_date = models.DateTimeField()

    class Meta:
        managed = False
        db_table = 'django_session'


class Journal(models.Model):
    name = models.CharField(max_length=20)
    project = models.ForeignKey('Project', models.DO_NOTHING, blank=True, null=True)
    author = models.CharField(max_length=20)
    content = models.CharField(max_length=1000)
    date = models.DateField()
    open = models.IntegerField()
    address = models.CharField(max_length=500, blank=True, null=True)
    stage = models.IntegerField(blank=True, null=True)
    examine = models.IntegerField(blank=True, null=True)

    class Meta:
        managed = False
        db_table = 'journal'


class Project(models.Model):
    name = models.CharField(max_length=20)
    introduce = models.CharField(max_length=50)
    concrete = models.CharField(max_length=5000)
    could = models.IntegerField()
    releasedate = models.DateField(db_column='releaseDate')  # Field name made lowercase.
    closingdate = models.DateField(db_column='closingDate')  # Field name made lowercase.
    applicationdate = models.DateField(db_column='applicationDate')  # Field name made lowercase.

    class Meta:
        managed = False
        db_table = 'project'


class User(models.Model):
    name = models.CharField(unique=True, max_length=20)
    number = models.IntegerField()
    email = models.CharField(max_length=20)
    phone = models.CharField(max_length=20)
    password = models.CharField(max_length=20)
    type = models.IntegerField()

    class Meta:
        managed = False
        db_table = 'user'


modelsに貼り付けpy
見つけたpy,モデルの登録
from manage.models import Journal,Project,User;


# Register your models here.
admin.site.register([Journal,Project,User])
その後、データを移行し、djangoが所有するバックグラウンド管理システムを使用して本プロジェクトのデータベースを管理します.