尝试迁移Django时遇到操作错误

时间:2015-12-02 16:21:32

标签: python sql django migration

每当我尝试在Django中迁移我的应用程序时,python manage.py migrate命令都会抛出操作错误:

django.db.utils.OperationalError: table "main_site_prescription" already exists

我尝试删除该表,但是没有用。我尝试--fake迁移,但数据库无法识别对models.py的更改。当我尝试使用视图中的一个列时,会在网站上抛出此内容:

Exception Type:     OperationalError
Exception Value:    table main_site_event has no column named initiated_by_id

以下是表格:

sqlite> .tables
auth_group                                  
auth_group_permissions                      
auth_permission                             
auth_user                                   
auth_user_groups                            
auth_user_user_permissions                  
django_admin_log                            
django_content_type                         
django_migrations                           
django_session                              
main_site_appointment                       
main_site_doctor                            
main_site_doctor_listOfPatients             
main_site_event                             
main_site_hospital                          
main_site_hospital_listOfDoctors            
main_site_hospital_listOfHospitalAdmins     
main_site_hospital_listOfNurses             
main_site_hospital_listOfPatients           
main_site_hospitaladmin                     
main_site_hospitaladmin_listOfDoctors       
main_site_hospitaladmin_listOfHospitalAdmins
main_site_hospitaladmin_listOfNurses        
main_site_hospitaladmin_listOfPatients      
main_site_message                           
main_site_nurse                             
main_site_nurse_listOfDoctors               
main_site_nurse_listOfPatients              
main_site_patient                           
main_site_patient_prescriptions             
main_site_patient_records                   
main_site_prescription                      
main_site_record 

这里是PRAGMA table_info(main_site_event)输出......

sqlite> PRAGMA table_info(main_site_event);
0|id|integer|1||1
1|activity|text|1||0
2|time|datetime|1||0
sqlite> 

这是模型中的表示......

'''Class representing an event, used for the activity log'''
class Event(models.Model):
    activity = models.TextField(max_length=500, blank=True) # an action from the list of actions
    time = models.DateTimeField(auto_now_add=True) # the time of the action in datetime format
    initiated_by = models.ForeignKey(User, related_name="initiator") # the user who initiated the action
    target_of = models.ForeignKey(User, default = None, related_name="target", null = True) # the user who is the target of the action
    hospitals = models.ForeignKey(Hospital, default=None, null = True)
    prescriptions = models.ForeignKey(Prescription, default=None, null = True)

哪个显然不正确(表缺少多列)

0 个答案:

没有答案