python-Django中鏈接MySQL數據庫及設置用戶名密碼

項目和應用建立好之後,進入當前的目錄所在的文件夾便可操做,也能夠用pycharm中的Tools工具運行manage.py,本人採用的是運行pycharm下的manage.py文件
配置:
1.把對應的應用添加到INSTALLED_APPS下,注意分號python

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'blog', #應用
]
2.修改數據庫鏈接mysql

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql', # 提示鏈接mysql數據庫
        'NAME': 'test', # 數據庫名爲test,要本身建立
        'USER': 'root', # 用戶名
        'PASSWORD': 'root',    # 密碼
        'HOST': '127.0.0.1', # 鏈接的主機
        'PORT': '3306', # 對應的端口號
    }
}
3.運行:sql

manage.py@hello_mysite > migrate # 鏈接數據庫
"D:\pycharm\PyCharm 5.0.3\bin\runnerw.exe" D:\python\python.exe "D:\pycharm\PyCharm 5.0.3\helpers\pycharm\django_manage.py" migrate G:/hello_mysite
Operations to perform:
  Apply all migrations: admin, auth, contenttypes, 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 sessions.0001_initial... OK
Process finished with exit code 0數據庫


manage.py@hello_mysite > makemigrations blog # 關聯應用
"D:\pycharm\PyCharm 5.0.3\bin\runnerw.exe" D:\python\python.exe "D:\pycharm\PyCharm 5.0.3\helpers\pycharm\django_manage.py" makemigrations blog G:/hello_mysite
No changes detected in app 'blog'
 
 
Process finished with exit code 0
manage.py@hello_mysite > createsuperuser # 建立超級用戶
"D:\pycharm\PyCharm 5.0.3\bin\runnerw.exe" D:\python\python.exe "D:\pycharm\PyCharm 5.0.3\helpers\pycharm\django_manage.py" createsuperuser G:/hello_mysite
Username:  root # 用戶名
Email address:  root@root.com # 郵箱
Warning: Password input may be echoed.
Password:  root1234 # 密碼,不要過短
Warning: Password input may be echoed.
Password (again):  root1234 # 再次輸入
Superuser created successfully.django

 

OK了!!session

相關文章
相關標籤/搜索