编程错误列不存在

时间:2016-10-07 20:04:20

标签: python django postgresql object models

models.py

class PlansToLodge(models.Model):
sm_sequence = models.IntegerField()
sm_year = models.IntegerField()    
location = models.TextField(blank=True, null=True)
car_number = models.CharField(max_length=100, blank=True, null=True)
client_or_owner = models.TextField(blank=True, null=True)
date_received = models.DateField(blank=True, null=True)
date_lodged = models.DateField(blank=True, null=True)
remarks = models.TextField(blank=True, null=True)
sent_or_received = models.TextField(blank=True, null=True)    
receipt_number = models.TextField(blank=True, null=True)

class Meta:
    managed = False
    db_table = 'plans_to_lodge'
    unique_together = (('sm_sequence', 'sm_year'),)

view.py

def searchPlanInfo(request):
logger = logging.getLogger(__name__)
if request.user.is_authenticated():
    if request.method =='POST':
        if request.POST['smYear'] is not '':
            searchPlan = request.POST['smYear']
            logger.error('lets see here')
            foundPlan = PlansToLodge.objects.filter(sm_year=searchPlan)
            logger.error(foundPlan[0])

            context = {'parcel_list': foundPlan}
            return render(request,'parcelmanager/index2.html',context)
        return HttpResponse("once again")

回溯

回溯:

File "C:\Users\yfevrier\Envs\landregtry1\lib\site-packages\django\core\handlers\base.py" in get_response
  132.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Sites\Landregistry\surveyplanmanager\views.py" in searchPlanInfo
  39.               logger.error(foundPlan[0])
File "C:\Users\yfevrier\Envs\landregtry1\lib\site-packages\django\db\models\query.py" in __getitem__
  201.         return list(qs)[0]
File "C:\Users\yfevrier\Envs\landregtry1\lib\site-packages\django\db\models\query.py" in __iter__
  162.         self._fetch_all()
File "C:\Users\yfevrier\Envs\landregtry1\lib\site-packages\django\db\models\query.py" in _fetch_all
  965.             self._result_cache = list(self.iterator())
File "C:\Users\yfevrier\Envs\landregtry1\lib\site-packages\django\db\models\query.py" in iterator
  238.         results = compiler.execute_sql()
File "C:\Users\yfevrier\Envs\landregtry1\lib\site-packages\django\db\models\sql\compiler.py" in execute_sql
  829.             cursor.execute(sql, params)
File "C:\Users\yfevrier\Envs\landregtry1\lib\site-packages\django\db\backends\utils.py" in execute
  79.             return super(CursorDebugWrapper, self).execute(sql, params)
File "C:\Users\yfevrier\Envs\landregtry1\lib\site-packages\django\db\backends\utils.py" in execute
  64.                 return self.cursor.execute(sql, params)
File "C:\Users\yfevrier\Envs\landregtry1\lib\site-packages\django\db\utils.py" in __exit__
  97.                 six.reraise(dj_exc_type, dj_exc_value, traceback)
File "C:\Users\yfevrier\Envs\landregtry1\lib\site-packages\django\utils\six.py" in reraise
  658.             raise value.with_traceback(tb)
File "C:\Users\yfevrier\Envs\landregtry1\lib\site-packages\django\db\backends\utils.py" in execute
  64.                 return self.cursor.execute(sql, params)

Exception Type: ProgrammingError at /surveyplanmanager/searchPlanInfo/
Exception Value: column plans_to_lodge.id does not exist
LINE 1: SELECT "plans_to_lodge"."id", "plans_to_lodge"."sm_sequence"...
               ^

现在在我使用sqlite之前,但我们进入了什么数据库,我们将使用Postgresql,我知道在sqlite中它创建了这些“id”字段,但我不知道为什么它这样做为postgresql ive迁移了所有这一切都不应该发生

1 个答案:

答案 0 :(得分:2)

实际上发生此错误是因为您的数据库未迁移

所以运行以下命令来迁移数据库

python manage.py migrate

如果未运行,请运行以下命令

python manage.py makemigrations
python manage.py migrate