前提・実現したいこと
django でmysqlの操作を試しているのですが、columnが下記のように日本語だとエラーが出てしまいます。
試しにテスト用のテーブルを作成し、columnを英数字にしたら問題なく処理ができました。
columnを日本語にしたままで、操作する方法はないのでしょうか?
発生している問題・エラーメッセージ
Internal Server Error: /myapp1/shipment-inputs/ Traceback (most recent call last): File "C:\Python\env1\lib\site-packages\django\core\handlers\exception.py", line 34, in inner response = get_response(request) File "C:\Python\env1\lib\site-packages\django\core\handlers\base.py", line 126, in _get_response response = self.process_exception_by_middleware(e, request) File "C:\Python\env1\lib\site-packages\django\core\handlers\base.py", line 124, in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) File "C:\Python\mysite\myapp1\views.py", line 101, in shipment_inputs tes = sh.getshipmentno() File "C:\Python\mysite\myapp1\shipments\tests.py", line 17, in getshipmentno print(sh.出荷番号) AttributeError: 'NoneType' object has no attribute '出荷番号' [18/Mar/2019 18:17:54] "POST /myapp1/shipment-inputs/ HTTP/1.1" 500 74315
該当のソースコード
django
1# tests.py 2 3#親ディレクトリからの参照方法 ↓三行 4import sys 5 6sys.path.append('../') 7from myapp1.models import * 8 9class tests(): 10 11 def __init__(self, cd): 12 self.cd = cd 13 14 def getshipmentno(self): 15 #b = Sqltes(id=self.cd, name="new name6", testext="new text6") 16 #b.save() 17 sh = Shipmentlist.objects.last() 18 print(sh.出荷番号)
django
1# models.py 2 3import datetime 4 5from django.db import models 6from django.utils import timezone 7 8class Shipmentlist(models.Model): 9 出荷番号 = models.IntegerField(primary_key=True) 10 受注日 = models.CharField(max_length=255, blank=True, null=True) 11 宛先コード = models.CharField(max_length=255, blank=True, null=True) 12 指図no_field = models.CharField(db_column='指図No.', max_length=255, blank=True, null=True) # Field name made lowercase. Field renamed to remove unsuitable characters. Field renamed because it ended with '_'. 13 出荷日 = models.CharField(max_length=255, blank=True, null=True) 14 納入日 = models.CharField(max_length=255, blank=True, null=True) 15 注文no_field = models.CharField(db_column='注文No.', max_length=50, blank=True, null=True) # Field name made lowercase. Field renamed to remove unsuitable characters. Field renamed because it ended with '_'. 16 17 class Meta: 18 managed = False 19 db_table = 'shipmentlist'
補足情報(FW/ツールのバージョンなど)
Command==0.1.0
Django==2.1.5
django-uikit-admin==0.1.1
django-uikit-editor==0.0.1
pytz==2018.9
Python 3.6.5
あなたの回答
tips
プレビュー