| DATABASES = { |
| 'default': { |
| 'ENGINE': 'django.db.backends.sqlite3', |
| 'NAME': BASE_DIR / 'db.sqlite3', |
| } |
| } |
- 项目根路径下会自动生成db.sqlite3
- 项目根路径下执行如下命令,生成数据库
| C:\work\bysms>python manage.py migrate |
| 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 admin.0003_logentry_add_action_flag_choices... 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 auth.0009_alter_user_last_name_max_length... OK |
| Applying auth.0010_alter_group_name_max_length... OK |
| Applying auth.0011_update_proxy_permissions... OK |
| Applying auth.0012_alter_user_first_name_max_length... OK |
| Applying sessions.0001_initial... OK |
- 使用chocolatey安装数据库sqlitestudio
| choco install sqlitestudio |

- 连接:Database -> Add a database


| # 新建1个包 |
| python manage.py startapp common |
| |
| # 在common包的models.py中编写如下 |
| from django.db import models |
| |
| class Customer(models.Model): |
| # 客户名称 |
| name = models.CharField(max_length=200) |
| # 联系电话 |
| phonenumber = models.CharField(max_length=200) |
| # 地址 |
| address = models.CharField(max_length=200) |
| |
| |
| INSTALLED_APPS = [ |
| 'common.apps.CommonConfig', |
| ] |
| |
| |
| INSTALLED_APPS = [ |
| |
| 'common', |
| ] |
| # 上面指定了django扫描common包,而common包又进行了修改,执行如下命令,会生成更行脚本 |
| C:\work\bysms>python manage.py makemigrations common |
| Migrations for 'common': |
| common\migrations\0001_initial.py |
| - Create model Customer |

| C:\work\bysms>python manage.py migrate |
| Operations to perform: |
| Apply all migrations: admin, auth, common, contenttypes, sessions |
| Running migrations: |
| Applying common.0001_initial... OK |
-
查看数据库

-
添加1个用户
| |
| C:\work\bysms>python manage.py createsuperuser |
| Username (leave blank to use 'ychen'): ychen |
| Email address: chniny@outlook.com |
| Password: |
| Password (again): |
| This password is too common. |
| Bypass password validation and create user anyway? [y/N]: y |
| Superuser created successfully. |

- 输入上面的用户名和密码



【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?