您的位置:首页 > 数据库 > SQL

django-----转储MySQL数据库

2017-11-13 17:05 302 查看
Django  

数据库授权授权访问用户:  GRANT ALL PRIVILEGES ON *.* TO 'csnd'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;   

FLUSH   PRIVILEGES; 

1、配置

      djanog settings.py文件:新增app
  

     INSTALLED_APPS = [

        'django.contrib.admin',

        'django.contrib.auth',

        'django.contrib.contenttypes',

        'django.contrib.sessions',

        'django.contrib.messages',

        'django.contrib.staticfiles',

        'csdn_app',         # ,不要忘记写

    ]

2、配置APP中的models.py

         class Publisher(models.Model):

         name = models.CharField(max_length=30)

         address = models.CharField(max_length=50)

         city = models.CharField(max_length=60)

         state_province = models.CharField(max_length=30)

         country = models.CharField(max_length=50)

         website = models.URLField()
 

3、生成迁移文件:根据模型类生成sql语句

         python manage.py makemigrations  csdn_app
Migrations for 'csdn_app':

             csdn_app/migrations/0001_initial.py

                - Create model BookInfo

                - Create model HeroInfo

 

4、执行迁移:执行sql语句生成数据表

         python manage.py migrate

            Operations to perform:

                Apply all migrations: admin, auth, contenttypes, csdn_app, sessions

                Running migrations:

                Applying contenttypes.0001_initial... OK

                Applying auth.0001_initial... OK

                Applying admin.0001_initial... OK

                Applying admin.0002_logentry_remove_auto_add... OK

                Applying contenttypes.0002_remove_content_type_name... OK

                Applying auth.0002_alter_permission_name_max_length... OK

                Applying auth.0003_alter_user_email_max_length... OK

                Applying auth.0004_alter_user_username_opts... OK

                Applying auth.0005_alter_user_last_login_null... OK

                Applying auth.0006_require_contenttypes_0002... OK

                Applying auth.0007_alter_validators_add_error_messages... OK

                Applying auth.0008_alter_user_username_max_length... OK

                Applying csdn_app.0001_initial... OK

                Applying sessions.0001_initial... OK

6、查看数据库、导入数据:

                 insert into 表名(key) values('values'),     
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  django 运维 数据