gpt4 book ai didi

python - ORA-01861 : literal does not match format string when executing get model object in django

转载 作者:太空狗 更新时间:2023-10-29 21:59:40 27 4
gpt4 key购买 nike

我在 django 中有一个模型对象,就像这样......

from django.db import models

class Person(models.Model):
employee_title = models.CharField(max_length=150)
pk_person_id = models.IntegerField(primary_key=True)
department_name = models.CharField(max_length=240)
cost_center = models.CharField(max_length=150)
user_name = models.CharField(max_length=100)

def __str__(self):
return self.user_name

class Meta:
managed = False
db_table = 'company_hr_idm_data_v'

在我看来,我正在像这样对 Person 对象做一个简单的获取...

testobj = Person.objects.using('oracle').get(pk=4)

代码出错时出现 DatabaseError

ORA-01861: literal does not match format string

这是我在 settings.py 中将 Debug模式设置为 true 时编写的堆栈跟踪

Environment:


Request Method: GET
Request URL: http://127.0.0.1:8000/roles/testing

Django Version: 1.7.2
Python Version: 2.7.6
Installed Applications:
('django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'roles')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware')


Traceback:
File "/Users/adjeibad/.virtualenvs/wwtmlserver/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
111. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Users/adjeibad/.virtualenvs/wwtmlserver/entitlements/roles/views/Organization.py" in test
9. testobj = Person.objects.using('oracle').get(pk=4)
File "/Users/adjeibad/.virtualenvs/wwtmlserver/lib/python2.7/site- packages/django/db/models/query.py" in get
351. num = len(clone)
File "/Users/adjeibad/.virtualenvs/wwtmlserver/lib/python2.7/site-packages/django/db/models/query.py" in __len__
122. self._fetch_all()
File "/Users/adjeibad/.virtualenvs/wwtmlserver/lib/python2.7/site-packages/django/db/models/query.py" in _fetch_all
966. self._result_cache = list(self.iterator())
File "/Users/adjeibad/.virtualenvs/wwtmlserver/lib/python2.7/site-packages/django/db/models/query.py" in iterator
265. for row in compiler.results_iter():
File "/Users/adjeibad/.virtualenvs/wwtmlserver/lib/python2.7/site-packages/django/db/models/sql/compiler.py" in results_iter
700. for rows in self.execute_sql(MULTI):
File "/Users/adjeibad/.virtualenvs/wwtmlserver/lib/python2.7/site-packages/django/db/models/sql/compiler.py" in execute_sql
786. cursor.execute(sql, params)
File "/Users/adjeibad/.virtualenvs/wwtmlserver/lib/python2.7/site-packages/django/db/backends/utils.py" in execute
81. return super(CursorDebugWrapper, self).execute(sql, params)
File "/Users/adjeibad/.virtualenvs/wwtmlserver/lib/python2.7/site-packages/django/db/backends/utils.py" in execute
65. return self.cursor.execute(sql, params)
File "/Users/adjeibad/.virtualenvs/wwtmlserver/lib/python2.7/site-packages/django/db/utils.py" in __exit__
94. six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/Users/adjeibad/.virtualenvs/wwtmlserver/lib/python2.7/site-packages/django/db/backends/utils.py" in execute
65. return self.cursor.execute(sql, params)
File "/Users/adjeibad/.virtualenvs/wwtmlserver/lib/python2.7/site- packages/django/db/backends/oracle/base.py" in execute
916. return self.cursor.execute(query, self._param_generator(params))

Exception Type: DatabaseError at /roles/testing
Exception Value: ORA-01861: literal does not match format string

哦!这也是生成的查询...

SELECT * FROM (SELECT ROWNUM AS "_RN", "_SUB".* FROM (SELECT "COMPANY_HR_IDM_DATA_V"."EMPLOYEE_TITLE", "COMPANY_HR_IDM_DATA_V"."PK_PERSON_ID", "COMPANY_HR_IDM_DATA_V"."DEPARTMENT_NAME", "COMPANY_HR_IDM_DATA_V"."COST_CENTER", "COMPANY_HR_IDM_DATA_V"."USER_NAME" FROM "COMPANY_HR_IDM_DATA_V" WHERE "COMPANY_HR_IDM_DATA_V"."PK_PERSON_ID" = :arg0) "_SUB" WHERE ROWNUM <= 21) WHERE "_RN" > 0

我尽量提供了尽可能多的信息,有人可以引导我朝着正确的方向前进吗?

最佳答案

您可以尝试通过提供输入直接执行查询吗?。输入和实际列类型之间可能存在数据类型差异。

关于python - ORA-01861 : literal does not match format string when executing get model object in django,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27913315/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com