Django小知识

Django知识小问答


Django知识小问答

关于makemigrations

问:我用python manage.py makemigrations怎么没能将我的model文件生成数据?

答:可以給我看下model的文件目录吗?

问:目录是这样的

1
2
3
4
5
6
7
8
(venv) G:\git\bigbooom\bigboomm\citizen>tree /f
卷 study 的文件夹 PATH 列表
卷序列号为 0000000F B64E:66E1
G:.
models.py
models.pyc
__init__.py
__init__.pyc

答:嗯嗯,我知道,我想你应该是少了一个migrations的文件夹吧,所以他不知道你需要生成migrations,你试试在citizen文件夹下面建一个migrations,记得要在里面加一个init.py哦,不然也是不可以的

问:啊,可以了~~ Good Job

1
2
3
4
(venv) G:\git\bigbooom\bigboomm>python manage.py makemigrations
Migrations for 'citizen':
citizen\migrations\0001_initial.py:
- Create model Citizen

答:其实,一般Django中建app建议用

manage.py startapp ```这个命令,这样可以帮你建立一个完整的app目录哦~~
1
2
3
4

## cryptography 错误

报`RuntimeError: cryptography is required for sha256_password or caching_sha2_password`错:

File “C:\Users\shikanon\Desktop\新建文件夹\venv\lib\site-packages\pymysql\connections.py”, line 325, in init
self.connect()
File “C:\Users\shikanon\Desktop\新建文件夹\venv\lib\site-packages\pymysql\connections.py”, line 599, in connect
self._request_authentication()
File “C:\Users\shikanon\Desktop\新建文件夹\venv\lib\site-packages\pymysql\connections.py”, line 882, in _request_authentication
auth_packet = _auth.caching_sha2_password_auth(self, auth_packet)
File “C:\Users\shikanon\Desktop\新建文件夹\venv\lib\site-packages\pymysql_auth.py”, line 264, in caching_sha2_password_auth
data = sha2_rsa_encrypt(conn.password, conn.salt, conn.server_public_key)
File “C:\Users\shikanon\Desktop\新建文件夹\venv\lib\site-packages\pymysql_auth.py”, line 142, in sha2_rsa_encrypt
raise RuntimeError(“cryptography is required for sha256_password or caching_sha2_password”)
RuntimeError: cryptography is required for sha256_password or caching_sha2_password

1
2
3

只要安装`cryptography`包就可以了:
```pip install cryptography

windows 二进制包下载

https://www.lfd.uci.edu/~gohlke/pythonlibs/

shikanon wechat
欢迎您扫一扫,订阅我滴↑↑↑的微信公众号!