我的模型定义为:
class NModels(models.Model):
model_name=models.TextField(max_length=30, default='DEFVAL')
class ModelRun(models.Model):
currmodel= models.ForeignKey(NModels)
run_name = models.TextField(max_length=20)
class ModelRegion(models.Model):
model_run = models.ForeignKey(ModelRun)
region = models.TextField(max_length=20)
class ModelImages(models.Model):
model_region = models.ForeignKey(ModelRegion)
map_type = models.TextField(max_length=20)
map_path = models.TextField(max_length=100)
当我提交表单时,调试返回:
Exception Value: column "model_name" of relation "wxpoint_nmodels" does not exist
LINE 1: INSERT INTO "wxpoint_nmodels" ("model_name") VALUES ('GFS')
在我的views.py中:
def model_page(request):
if request.method =='POST':
new_model_image = request.POST['GFS']
gfsmodel = NModels.objects.create(model_name=new_model_image)
currentmodelrun = ModelRun.objects.create(currmodel=gfsmodel, run_name='gfs00z')
currentmodelregion = ModelRegion.objects.create(model_run=currentmodelrun, region='USA')
myimage = ModelImages.objects.create(model_region=currentmodelregion, map_type="temps",
map_path='images/GFS2mt12z.gif', timestep="00hr")
return render(request, 'models.html', {'new_model_image': myimage.map_path, })
return render(request, 'models.html')
当我运行单元测试时,一切正常,所以我不确定为什么我会收到此错误。
我已经完成python3 manage.py进行迁移,迁移,syncdb仍然得到相同的错误。在psql中,\ l显示了我的应用程序的数据库,尽管\ d不返回找到的关系。
编辑:
python3 manage.py showmigrations yield:
admin
[X] 0001_initial
auth
[X] 0001_initial
[X] 0002_alter_permission_name_max_length
[X] 0003_alter_user_email_max_length
[X] 0004_alter_user_username_opts
[X] 0005_alter_user_last_login_null
[X] 0006_require_contenttypes_0002
contenttypes
[X] 0001_initial
[X] 0002_remove_content_type_name
sessions
[X] 0001_initial
wxpoint
[X] 0001_initial
[X] 0002_modelrun
[X] 0003_modelregion
[X] 0004_modelimages
[X] 0005_auto_20150611_0341
EDIT2:
运行python3 manage.py dbshell
然后\d+ wxpoint_nmodels
:
Column | Type | Modifiers | Storage | Stats target | Description
--------+---------+--------------------------------------------------------------+---------+--------------+-------------
id | integer | not null default nextval('wxpoint_nmodels_id_seq'::regclass) | plain | |