V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX  ›  mw717if  ›  全部回复第 2 页 / 共 2 页
回复总数  32
1  2  
2020-03-24 18:01:27 +08:00
回复了 mw717if 创建的主题 Python Python 同步数据库, mysql 报错 1064
@wuwukai007 我配置了 if_exists='delete',
fast_sql.to_sql(sql, from_db=con, to_db=to_db, if_exists='delete', mode='rw', to_table=table,
delete_cache=True, show_progress=True, )
为什么还会报错 pymysql.err.IntegrityError: (1062, "Duplicate entry '509298289133400064' for key 'PRIMARY'")
2020-02-06 15:58:48 +08:00
回复了 mw717if 创建的主题 Python Python 同步数据库, mysql 报错 1064
@wuwukai007 大佬报错了
res = fast_sql.to_sql(sql, from_db=con, to_db=to_db, if_exists='delete', mode='rw', to_table=table,
delete_cache=True, show_progress=True, )


Traceback (most recent call last):

File "/home/v2ex/PycharmProjects/test_project/app/util/syncdb.py", line 27, in syncdb
delete_cache=True, show_progress=False, )
File "/home/v2ex/.local/lib/python3.6/site-packages/fast_sql/__init__.py", line 360, in to_sql
parse_dates=parse_dates, columns=columns,
File "/home/v2ex/.local/lib/python3.6/site-packages/fast_sql/fastsql/sql.py", line 308, in rsync_db
self.decision()
File "/home/v2ex/.local/lib/python3.6/site-packages/fast_sql/fastsql/sql.py", line 274, in decision
self.write_db()
File "/home/v2ex/.local/lib/python3.6/site-packages/fast_sql/utils/common.py", line 94, in hander
raise e
File "/home/v2ex/.local/lib/python3.6/site-packages/fast_sql/utils/common.py", line 91, in hander
fun(*args, **kwargs)
File "/home/v2ex/.local/lib/python3.6/site-packages/fast_sql/fastsql/sql.py", line 372, in write_db
self.insert_db()
File "/home/v2ex/.local/lib/python3.6/site-packages/fast_sql/fastsql/sql.py", line 394, in insert_db
raise e
File "/home/v2ex/.local/lib/python3.6/site-packages/fast_sql/fastsql/sql.py", line 391, in insert_db
db.executemany(sql, df.values.tolist())
File "/home/v2ex/.local/lib/python3.6/site-packages/DBUtils/SteadyDB.py", line 605, in tough_method
result = method(*args, **kwargs) # try to execute
File "/home/v2ex/.local/lib/python3.6/site-packages/pymysql/cursors.py", line 197, in executemany
self._get_db().encoding)
File "/home/v2ex/.local/lib/python3.6/site-packages/pymysql/cursors.py", line 213, in _do_execute_many
v = values % escape(next(args), conn)
File "/home/v2ex/.local/lib/python3.6/site-packages/pymysql/cursors.py", line 122, in _escape_args
return tuple(conn.literal(arg) for arg in args)
File "/home/v2ex/.local/lib/python3.6/site-packages/pymysql/cursors.py", line 122, in <genexpr>
return tuple(conn.literal(arg) for arg in args)
File "/home/v2ex/.local/lib/python3.6/site-packages/pymysql/connections.py", line 467, in literal
return self.escape(obj, self.encoders)
File "/home/v2ex/.local/lib/python3.6/site-packages/pymysql/connections.py", line 460, in escape
return converters.escape_item(obj, self.charset, mapping=mapping)
File "/home/v2ex/.local/lib/python3.6/site-packages/pymysql/converters.py", line 27, in escape_item
val = encoder(val, mapping)
File "/home/v2ex/.local/lib/python3.6/site-packages/pymysql/converters.py", line 118, in escape_unicode
return u"'%s'" % _escape_unicode(value)
File "/home/v2ex/.local/lib/python3.6/site-packages/pymysql/converters.py", line 73, in _escape_unicode
return value.translate(_escape_table)
AttributeError: 'Timestamp' object has no attribute 'translate'
2020-02-05 21:49:03 +08:00
回复了 mw717if 创建的主题 Python Python 同步数据库, mysql 报错 1064
@wuwukai007

#1.在线迁移
sql = "select * from student where id <1000000"
con = create_engine("oracle+cx_oracle://wuwukai:test@localhost:1521/helowin")
to_db = create_engine("mysql+pymysql://root:123456@localhost:3306/aps_2")
res = fast_sql.to_sql(sql,from_db=con,to_db=to_db,if_exists='delete',
mode='rw',to_table='stu',delete_cache=True,show_progress=True,)

用这个语句对吗 我理解的是直接"select * from table " 这样就相当于同步所有数据到新库了
2020-02-05 21:36:47 +08:00
回复了 mw717if 创建的主题 Python Python 同步数据库, mysql 报错 1064
@wuwukai007 主要为了之后做到 apscheduler 定时任务中
2020-02-05 21:35:52 +08:00
回复了 mw717if 创建的主题 Python Python 同步数据库, mysql 报错 1064
@wuwukai007 创建 sql 文件、写入新库 这个过程写在 flask 的脚本里,所以就用 pymysql 处理文件中的 sql 语句了
上班时间 9:30-15:30...没打错吗
2019-09-03 09:35:02 +08:00
回复了 mw717if 创建的主题 优惠信息 天猫新活动章鱼组队
今日继续¥ e1BUYPzbrNK ¥
2019-09-02 09:09:33 +08:00
回复了 mw717if 创建的主题 优惠信息 天猫新活动章鱼组队
今日大章鱼¥ Q1G2YPsevFE ¥
2018-12-06 16:41:00 +08:00
回复了 qiayue 创建的主题 推广 软糯香甜有嚼劲的倒蒸番薯干又来了 [所有 V 友回帖即可抽奖]
我来组成分组
1  2  
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2805 人在线   最高记录 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 19ms · UTC 09:39 · PVG 17:39 · LAX 01:39 · JFK 04:39
Developed with CodeLauncher
♥ Do have faith in what you're doing.