创建数据库
- 项目中数据库的配置在 bysms/settings.py 中,这里 默认使用sqlite3
```python
Database
https://docs.djangoproject.com/en/2.0/ref/settings/#databases
DATABASES = { ‘default’: { ‘ENGINE’: ‘django.db.backends.sqlite3’, ‘NAME’: os.path.join(BASE_DIR, ‘db.sqlite3’), } }
- 初始化数据库根据setting文件中配置生成表 `python manage.py migrate````pythonPS D:\86176\Documents\projects\myapps> python manage.py migrateOperations to perform:Apply all migrations: admin, auth, contenttypes, sessionsRunning migrations:Applying contenttypes.0001_initial... OKApplying auth.0001_initial... OKApplying admin.0001_initial... OKApplying admin.0002_logentry_remove_auto_add... OKApplying admin.0003_logentry_add_action_flag_choices... OKApplying contenttypes.0002_remove_content_type_name... OKApplying auth.0002_alter_permission_name_max_length... OKApplying auth.0003_alter_user_email_max_length... OKApplying auth.0004_alter_user_username_opts... OKApplying auth.0005_alter_user_last_login_null... OKApplying auth.0006_require_contenttypes_0002... OKApplying auth.0007_alter_validators_add_error_messages... OKApplying auth.0008_alter_user_username_max_length... OKApplying auth.0009_alter_user_last_name_max_length... OKApplying auth.0010_alter_group_name_max_length... OKApplying auth.0011_update_proxy_permissions... OKApplying auth.0012_alter_user_first_name_max_length... OKApplying sessions.0001_initial... OK
定义数据库表
PS D:\86176\Documents\projects\myapps> python .\manage.py makemigrations commonMigrations for 'common':common\migrations\0001_initial.pyPS D:\86176\Documents\projects\myapps> python .\manage.py migrateOperations to perform:Apply all migrations: admin, auth, common, contenttypes, sessionsRunning migrations:PS D:\86176\Documents\projects\myapps> python .\manage.py makemigrations commonYou are trying to add a non-nullable field 'qq' to customer without a default; we can't do that (the database needs something to populate existing rows).Please select a fix:column)2) Quit, and let me add a default in models.pyPS D:\86176\Documents\projects\myapps> python .\manage.py makemigrations commonMigrations for 'common':common\migrations\0002_customer_qq.py- Add field qq to customerPS D:\86176\Documents\projects\myapps> python .\manage.py migrateOperations to perform:Apply all migrations: admin, auth, common, contenttypes, sessionsRunning migrations:Applying common.0002_customer_qq... OKPS D:\86176\Documents\projects\myapps> python .\manage.py migrateOperations to perform:Apply all migrations: admin, auth, common, contenttypes, sessionsRunning migrations:No migrations to apply.PS D:\86176\Documents\projects\myapps> python .\manage.py creatsuperuserUnknown command: 'creatsuperuser'. Did you mean createsuperuser?Type 'manage.py help' for usage.PS D:\86176\Documents\projects\myapps> python manage.py createsuperuserUsername (leave blank to use '86176'): admindEmail address: 00000000Error: Enter a valid email address.Email address: yhzczyyx@163.comPassword:Password (again):This password is too short. It must contain at least 8 characters.This password is too common.This password is entirely numeric.Bypass password validation and create user anyway? [y/N]: ySuperuser created successfully.PS D:\86176\Documents\projects\myapps>
