创建数据库

DATABASES = { ‘default’: { ‘ENGINE’: ‘django.db.backends.sqlite3’, ‘NAME’: os.path.join(BASE_DIR, ‘db.sqlite3’), } }

  1. - 初始化数据库根据setting文件中配置生成表 `python manage.py migrate`
  2. ```python
  3. PS D:\86176\Documents\projects\myapps> python manage.py migrate
  4. Operations to perform:
  5. Apply all migrations: admin, auth, contenttypes, sessions
  6. Running migrations:
  7. Applying contenttypes.0001_initial... OK
  8. Applying auth.0001_initial... OK
  9. Applying admin.0001_initial... OK
  10. Applying admin.0002_logentry_remove_auto_add... OK
  11. Applying admin.0003_logentry_add_action_flag_choices... OK
  12. Applying contenttypes.0002_remove_content_type_name... OK
  13. Applying auth.0002_alter_permission_name_max_length... OK
  14. Applying auth.0003_alter_user_email_max_length... OK
  15. Applying auth.0004_alter_user_username_opts... OK
  16. Applying auth.0005_alter_user_last_login_null... OK
  17. Applying auth.0006_require_contenttypes_0002... OK
  18. Applying auth.0007_alter_validators_add_error_messages... OK
  19. Applying auth.0008_alter_user_username_max_length... OK
  20. Applying auth.0009_alter_user_last_name_max_length... OK
  21. Applying auth.0010_alter_group_name_max_length... OK
  22. Applying auth.0011_update_proxy_permissions... OK
  23. Applying auth.0012_alter_user_first_name_max_length... OK
  24. Applying sessions.0001_initial... OK

定义数据库表

  1. PS D:\86176\Documents\projects\myapps> python .\manage.py makemigrations common
  2. Migrations for 'common':
  3. common\migrations\0001_initial.py
  4. PS D:\86176\Documents\projects\myapps> python .\manage.py migrate
  5. Operations to perform:
  6. Apply all migrations: admin, auth, common, contenttypes, sessions
  7. Running migrations:
  8. PS D:\86176\Documents\projects\myapps> python .\manage.py makemigrations common
  9. You 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).
  10. Please select a fix:
  11. column)
  12. 2) Quit, and let me add a default in models.py
  13. PS D:\86176\Documents\projects\myapps> python .\manage.py makemigrations common
  14. Migrations for 'common':
  15. common\migrations\0002_customer_qq.py
  16. - Add field qq to customer
  17. PS D:\86176\Documents\projects\myapps> python .\manage.py migrate
  18. Operations to perform:
  19. Apply all migrations: admin, auth, common, contenttypes, sessions
  20. Running migrations:
  21. Applying common.0002_customer_qq... OK
  22. PS D:\86176\Documents\projects\myapps> python .\manage.py migrate
  23. Operations to perform:
  24. Apply all migrations: admin, auth, common, contenttypes, sessions
  25. Running migrations:
  26. No migrations to apply.
  27. PS D:\86176\Documents\projects\myapps> python .\manage.py creatsuperuser
  28. Unknown command: 'creatsuperuser'. Did you mean createsuperuser?
  29. Type 'manage.py help' for usage.
  30. PS D:\86176\Documents\projects\myapps> python manage.py createsuperuser
  31. Username (leave blank to use '86176'): admind
  32. Email address: 00000000
  33. Error: Enter a valid email address.
  34. Email address: yhzczyyx@163.com
  35. Password:
  36. Password (again):
  37. This password is too short. It must contain at least 8 characters.
  38. This password is too common.
  39. This password is entirely numeric.
  40. Bypass password validation and create user anyway? [y/N]: y
  41. Superuser created successfully.
  42. PS D:\86176\Documents\projects\myapps>