py3,数据没办法插入的问题
来源:3-20 IMOOCC工程用到的表models定义和字段设计
qq_疍疍_0
2020-05-01
ssh login and exec command:%s {‘info’: (‘192.168.1.100’, 22, ‘root’, ‘123456’), ‘status’: ‘success’, ‘cat /etc/issue’: b’\S\nKernel \r on an \m\n\n’, ‘cat /etc/redhat-release’: b’CentOS Linux release 7.7.1908 (Core)\n’, ‘hostname’: b’mikechenPC\n’, “cat /sys/class/net/[^vtlsb]*/address||esxcfg-vmknic -l|awk ‘{print $8}’|grep ‘:’”: b’02:42:33:39:8c:57\n6c:62:6d:fb:2c:cf\n’, ‘dmidecode -s system-serial-number’: b’To be filled by O.E.M.\n’, ‘dmidecode -s system-manufacturer’: b’MSI\n’, ‘dmidecode -s system-product-name’: b’MS-7680\n’}
Password Login … {‘192.168.1.100’: (‘22’, ‘123456’, ‘root’, b’CentOS Linux 7.7’, b’mikechenPC\n’, b’024233398c57_6c626dfb2ccf_’, b’TobefilledbyO.E.M.\n’, b’MSIMS-7680’)} {}
Key Login … {} {}
(535, b’Error: authentication failed’)
Traceback (most recent call last):
File “/usr/local/lib/python3.6/site-packages/django/db/backends/utils.py”, line 64, in execute
return self.cursor.execute(sql, params)
File “/usr/local/lib/python3.6/site-packages/django/db/backends/mysql/base.py”, line 124, in execute
return self.cursor.execute(query, args)
File “/usr/local/lib/python3.6/site-packages/pymysql/cursors.py”, line 165, in execute
result = self._query(query)
File “/usr/local/lib/python3.6/site-packages/pymysql/cursors.py”, line 321, in _query
conn.query(q)
File “/usr/local/lib/python3.6/site-packages/pymysql/connections.py”, line 860, in query
self._affected_rows = self._read_query_result(unbuffered=unbuffered)
File “/usr/local/lib/python3.6/site-packages/pymysql/connections.py”, line 1061, in _read_query_result
result.read()
File “/usr/local/lib/python3.6/site-packages/pymysql/connections.py”, line 1349, in read
first_packet = self.connection._read_packet()
File “/usr/local/lib/python3.6/site-packages/pymysql/connections.py”, line 1018, in _read_packet
packet.check_error()
File “/usr/local/lib/python3.6/site-packages/pymysql/connections.py”, line 384, in check_error
err.raise_mysql_exception(self._data)
File “/usr/local/lib/python3.6/site-packages/pymysql/err.py”, line 107, in raise_mysql_exception
raise errorclass(errno, errval)
pymysql.err.IntegrityError: (1452, ‘Cannot add or update a child row: a foreign key constraint fails (imoocc
.othermachineinfo
, CONSTRAINT othermachineinfo_oth_cab_id_bb1d61c8_fk_cabinetinfo_id
FOREIGN KEY (oth_cab_id
) REFERENCES cabinetinfo
(id
) ON DELETE CASCADE ON UPDATE CASCADE)’)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File “/home/mike/imoocc_py3/main.py”, line 205, in
main()
File “/home/mike/imoocc_py3/main.py”, line 110, in main
OtherMachineInfo.objects.create(ip=item,sn_key=other_sn,reson_str=u"IP存活,非Linux服务器",oth_cab_id=1)
File “/usr/local/lib/python3.6/site-packages/django/db/models/manager.py”, line 127, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File “/usr/local/lib/python3.6/site-packages/django/db/models/query.py”, line 348, in create
obj.save(force_insert=True, using=self.db)
File “/usr/local/lib/python3.6/site-packages/django/db/models/base.py”, line 734, in save
force_update=force_update, update_fields=update_fields)
File “/usr/local/lib/python3.6/site-packages/django/db/models/base.py”, line 762, in save_base
updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
File “/usr/local/lib/python3.6/site-packages/django/db/models/base.py”, line 846, in _save_table
result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
File “/usr/local/lib/python3.6/site-packages/django/db/models/base.py”, line 885, in _do_insert
using=using, raw=raw)
File “/usr/local/lib/python3.6/site-packages/django/db/models/manager.py”, line 127, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File “/usr/local/lib/python3.6/site-packages/django/db/models/query.py”, line 920, in _insert
return query.get_compiler(using=using).execute_sql(return_id)
File “/usr/local/lib/python3.6/site-packages/django/db/models/sql/compiler.py”, line 974, in execute_sql
cursor.execute(sql, params)
File “/usr/local/lib/python3.6/site-packages/django/db/backends/utils.py”, line 79, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File “/usr/local/lib/python3.6/site-packages/django/db/backends/utils.py”, line 64, in execute
return self.cursor.execute(sql, params)
File “/usr/local/lib/python3.6/site-packages/django/db/utils.py”, line 98, in exit
six.reraise(dj_exc_type, dj_exc_value, traceback)
File “/usr/local/lib/python3.6/site-packages/django/utils/six.py”, line 685, in reraise
raise value.with_traceback(tb)
File “/usr/local/lib/python3.6/site-packages/django/db/backends/utils.py”, line 64, in execute
return self.cursor.execute(sql, params)
File “/usr/local/lib/python3.6/site-packages/django/db/backends/mysql/base.py”, line 124, in execute
return self.cursor.execute(query, args)
File “/usr/local/lib/python3.6/site-packages/pymysql/cursors.py”, line 165, in execute
result = self._query(query)
File “/usr/local/lib/python3.6/site-packages/pymysql/cursors.py”, line 321, in _query
conn.query(q)
File “/usr/local/lib/python3.6/site-packages/pymysql/connections.py”, line 860, in query
self._affected_rows = self._read_query_result(unbuffered=unbuffered)
File “/usr/local/lib/python3.6/site-packages/pymysql/connections.py”, line 1061, in _read_query_result
result.read()
File “/usr/local/lib/python3.6/site-packages/pymysql/connections.py”, line 1349, in read
first_packet = self.connection._read_packet()
File “/usr/local/lib/python3.6/site-packages/pymysql/connections.py”, line 1018, in _read_packet
packet.check_error()
File “/usr/local/lib/python3.6/site-packages/pymysql/connections.py”, line 384, in check_error
err.raise_mysql_exception(self._data)
File “/usr/local/lib/python3.6/site-packages/pymysql/err.py”, line 107, in raise_mysql_exception
raise errorclass(errno, errval)
django.db.utils.IntegrityError: (1452, ‘Cannot add or update a child row: a foreign key constraint fails (imoocc
.othermachineinfo
, CONSTRAINT othermachineinfo_oth_cab_id_bb1d61c8_fk_cabinetinfo_id
FOREIGN KEY (oth_cab_id
) REFERENCES cabinetinfo
(id
) ON DELETE CASCADE ON UPDATE CASCADE)’)
1回答
-
Jeson
2020-05-02
这个表示,有一个外健表没有对应数值。
我建议查下othermachineinfo,在插入数据的时候把变量打印出来,可能在扫描的时候没有满足要求,导致数据没有提前插入。
一般这种情况和环境的一致性有关,需要自己一步步排查的。
00
相似问题