2013-05-13 26 views
0

我正在嘗試在此表中創建一條記錄,但失敗了。請有人告訴我一個例子,如何創建使用ApplicationStage.objects.create(...............)如何使用此型號創建記錄

class ApplicationStage(Base): 
    stage_id = models.AutoField(primary_key=True) 
    leave_id = models.ForeignKey(Leave) 
    auth_id = models.ForeignKey(ApproveAuthority) 
    approve_status_id = models.ForeignKey(Status) 
    approve_total_day = models.PositiveIntegerField(default=0) 
    comment = models.TextField() 
    approved_time = models.DateTimeField(auto_now_add=True) 
    is_livedate = models.CharField(choices=(("yes","Yes"), 
              ("no","No"), 
              ),max_length=15) 
+5

「失敗」並沒有真正告訴我們很多。它爲什麼會失敗,出現什麼錯誤信息? – dutt 2013-05-13 07:24:40

+0

您可以嘗試在模型實例上發出full_clean()方法,然後捕獲並打印該異常。可能會提供有關所得錯誤的更多信息:https://docs.djangoproject.com/en/dev/ref/models/instances/#django.db.models.Model.full_clean – 2013-05-13 07:53:28

回答

1

導航在這個表中的記錄到目錄到你的應用程序並運行:

python manage.py shell 

然後導入模型:

from your_app_name.models import ApplicationStage 

然後使用以下命令創建一條記錄:

a = ApplicationStage(stage_id=1, leave_id=1, auth_id .......... and so on) 
a.save()