質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Django

DjangoはPythonで書かれた、オープンソースウェブアプリケーションのフレームワークです。複雑なデータベースを扱うウェブサイトを開発する際に必要な労力を減らす為にデザインされました。

Model

MVCモデルの一部であるModelはアプリケーションで扱うデータとその動作を管理するために扱います。

Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

Q&A

0回答

464閲覧

DjangoのmodelでTypeError: write() argument must be str, not bytesが出る

退会済みユーザー

退会済みユーザー

総合スコア0

Django

DjangoはPythonで書かれた、オープンソースウェブアプリケーションのフレームワークです。複雑なデータベースを扱うウェブサイトを開発する際に必要な労力を減らす為にデザインされました。

Model

MVCモデルの一部であるModelはアプリケーションで扱うデータとその動作を管理するために扱います。

Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

0グッド

0クリップ

投稿2020/05/24 02:37

編集2020/05/24 02:46

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

とのみ表示されてエラーは出ません。

原因がわからないので困っています。

どうぞよろしくお願いいたします。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問