http://docs.djangoproject.jp/en/latest/intro/tutorial02.html
を参考にして、ホームページを作っています。
今、
TypeError: 'class Meta' got invalid attribute(s): table_name
とエラーが出ています。
Traceback (most recent call last): File "./manage.py", line 15, in <module> execute_from_command_line(sys.argv) File "/Users/xxx/django/django/core/management/__init__.py", line 365, in execute_from_command_line utility.execute() File "/Users/xxx/django/django/core/management/__init__.py", line 341, in execute django.setup() File "/Users/xxx/django/django/__init__.py", line 24, in setup apps.populate(settings.INSTALLED_APPS) File "/Users/xxx/django/django/apps/registry.py", line 112, in populate app_config.import_models() File "/Users/xxx/django/django/apps/config.py", line 198, in import_models self.models_module = import_module(models_module_name) File "/Users/xxx/anaconda/envs/py36/lib/python3.6/importlib/__init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 978, in _gcd_import File "<frozen importlib._bootstrap>", line 961, in _find_and_load File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 655, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 678, in exec_module File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed File "/Users/xxx/djangostudy/polls/models.py", line 4, in <module> class Question(models.Model): File "/Users/xxx/django/django/db/models/base.py", line 114, in __new__ new_class.add_to_class('_meta', Options(meta, app_label)) File "/Users/xxx/django/django/db/models/base.py", line 321, in add_to_class value.contribute_to_class(cls, name) File "/Users/xxx/django/django/db/models/options.py", line 197, in contribute_to_class raise TypeError("'class Meta' got invalid attribute(s): %s" % ','.join(meta_attrs)) TypeError: 'class Meta' got invalid attribute(s): table_name
とTracebackに言われました。
models.pyには
from django.db import models # Create your models here. class Question(models.Model): class Meta: app_label = 'polls' verbose_name = '質問' table_name = 'polls_question' # question_text = models.CharField(max_length=200) # pub_date = models.DateTimeField('date published') class Choice(models.Model): question = models.ForeignKey(Question,on_delete=models.CASCADE) # question = models.ForeignKey('polls.Question',on_delete=models.CASCADE) choice_text = models.CharField(max_length=200) votes = models.IntegerField(default=0)
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。