天天看點

Django小知識

Django知識小問答

Django知識小問答

關于makemigrations

問:我用python manage.py makemigrations怎麼沒能将我的model檔案生成資料?

答:可以給我看下model的檔案目錄嗎?

問:目錄是這樣的

(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

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

複制

答:其實,一般Django中建app建議用

## 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

隻要安裝`cryptography`包就可以了:
```pip install cryptography           

複制

windows 二進制包下載下傳

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