最初にEmployeeのクラスを作成しましたが、Employee.user_nameなどのクラス名でそのプロパティにアクセスすると、エラーが発生しました。理由はわかりません:django.db.models.Modelがプロパティーにアクセスできない
from django.db import models
import uuid
class Employee(models.Model):
employee_id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
user_name = models.CharField(max_length=30)
pwd = models.CharField(max_length=50)
first_name = models.CharField(max_length=50)
last_name = models.CharField(max_length=50)
email = models.EmailField()
entry_date = models.DateTimeField(auto_now=True, editable=False)
def __str__(self):
return self.user_name
the error is below:
>>> Employee.user_name
Traceback (most recent call last):
File "<console>", line 1, in <module>
AttributeError: type object 'Employee' has no attribute 'user_name'
>>>
あなたはどのコードを実行していますか、どのようなエラーが表示されていますか? – alecxe
このエラーを引き起こすコードを表示できますか? 'employee.user_name'(小文字で始まる)としてアクセスする必要があります – serg
コードはprint(Employee.user_name)です。エラーは次のとおりです。Employeeにuser_nameという属性がありません – Miles