【发布时间】:2020-10-18 15:50:46
【问题描述】:
我是pycharm控制台中的以下代码,我的日期长度明显小于提到的字段大小,那么为什么会出现这个错误
我的代码
df=pd.read_csv('/home/asif/Documents/Projects/TaxVisor/legal.txt',header=None,names=['type'])
for type in df['type']:
... print(type)
... print(len(type))
... LegalElement.objects.create(type=df['type'])
我的模特:
类 LegalElement(models.Model): type = models.CharField(max_length=25, null=False)
我的数据(来自 CSV)
PTY LTD
PTY. LTD
PTY. LIMITED
PTY. LTD.
PTY LTD.
PTY LIMITED
PROPRIETARY LTD.
PROPRIETARY LTD
PROPRIETARY LIMITED
我的数据库
create table company_registration_legalelement
(
id serial not null
constraint company_registration_legalelement_pkey
primary key,
type varchar(25) not null
);
我的错误:
Traceback (most recent call last):
File "/home/asif/DevProjects/taxvisor/venv/lib/python3.8/site-packages/django/db/backends/utils.py", line 86, in _execute
return self.cursor.execute(sql, params)
psycopg2.errors.StringDataRightTruncation: value too long for type character varying(25)
【问题讨论】:
-
你能显示
for type in df['type']:sn-p 的输出吗?这也是完整的 CSV 数据集吗?
标签: python django postgresql django-models