Djangoのmodelに
python
1user_screen = models.CharField(max_length=100)
というフィールドを追加して、「python manage.py makemigrations」しようとしたところ、それまで特に問題なかったのですが、
下記のエラーがでました。 (環境はMac、Python3.7.6、Django3.0)
Traceback (most recent call last): File "manage.py", line 21, in <module> main() File "manage.py", line 17, in main execute_from_command_line(sys.argv) File "C:\Users\Windows\Documents\pythonfiles\django\venv\tutorial\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line utility.execute() File "C:\Users\Windows\Documents\pythonfiles\django\venv\tutorial\lib\site-packages\django\core\management\__init__.py", line 395, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "C:\Users\Windows\Documents\pythonfiles\django\venv\tutorial\lib\site-packages\django\core\management\base.py", line 328, in run_from_argv self.execute(*args, **cmd_options) File "C:\Users\Windows\Documents\pythonfiles\django\venv\tutorial\lib\site-packages\django\core\management\base.py", line 369, in execute output = self.handle(*args, **options) File "C:\Users\Windows\Documents\pythonfiles\django\venv\tutorial\lib\site-packages\django\core\management\base.py", line 83, in wrapped res = handle_func(*args, **kwargs) File "C:\Users\Windows\Documents\pythonfiles\django\venv\tutorial\lib\site-packages\django\core\management\commands\makemigrations.py", line 168, in handle migration_name=self.migration_name, File "C:\Users\Windows\Documents\pythonfiles\django\venv\tutorial\lib\site-packages\django\db\migrations\autodetector.py", line 43, in changes changes = self._detect_changes(convert_apps, graph) File "C:\Users\Windows\Documents\pythonfiles\django\venv\tutorial\lib\site-packages\django\db\migrations\autodetector.py", line 185, in _detect_changes self.generate_added_fields() File "C:\Users\Windows\Documents\pythonfiles\django\venv\tutorial\lib\site-packages\django\db\migrations\autodetector.py", line 850, in generate_added_fields self._generate_added_field(app_label, model_name, field_name) File "C:\Users\Windows\Documents\pythonfiles\django\venv\tutorial\lib\site-packages\django\db\migrations\autodetector.py", line 871, in _generate_added_field field.default = self.questioner.ask_not_null_addition(field_name, model_name) File "C:\Users\Windows\Documents\pythonfiles\django\venv\tutorial\lib\site-packages\django\db\migrations\questioner.py", line 153, in ask_not_null_addition "Quit, and let me add a default in models.py", File "C:\Users\Windows\Documents\pythonfiles\django\venv\tutorial\lib\site-packages\django\db\migrations\questioner.py", line 95, in _choice_input print(question) File "C:\Users\Windows\AppData\Local\Programs\Python\Python37-32\lib\codecs.py", line 378, in write self.stream.write(data) TypeError: write() argument must be str, not bytes
エラーが起こった時のファイルはこちらです
model
1from django.db import models 2 3# Create your models here. 4class TwitterModel(models.Model): 5 6 class Meta: 7 #テーブル名の指定 8 db_table ="category" 9 10 user_screen = models.CharField(max_length=100) 11 user_name = models.CharField(max_length=140) 12 user_id = models.CharField(max_length=140) 13 user_img = models.CharField(max_length=140) 14 user_text = models.TextField(null=True) 15 user_created_at = models.CharField(max_length=140)
試してみたこと
user_screen = models.CharField(max_length=100)
を外すと
No changes detected
とのみ表示されてエラーは出ません。
原因がわからないので困っています。
どうぞよろしくお願いいたします。
あなたの回答
tips
プレビュー