我有代码1451的mysql错误.
无法删除或更新父行:外键约束失败(
online_store_admin.osa_admin_logs,CONSTRAINTfk_admins_logsFOREIGN KEY(aid)REFERENCESosa_admins(aid))
这里是sql语句:
drop table if exists osa_admins; create table if not exists osa_admins( aid int unsigned not null auto_increment, uid varchar(50) not null, pass char(41) not null, erp_id int unsigned not null, last_login int unsigned not null, is_block tinyint unsigned not null, menus varchar(50) not null, is_login tinyint unsigned not null, ip_login char(15) not null, constraint idx_osa_admins primary key using btree(aid) ); insert into osa_admins value …
我是 postgresql 的新手,当我测试插入代码时,我收到以下错误消息
错误异常('错误','23505','重复键值违反唯一约束“foo_column_key”');
我曾尝试在 cursor.execute() 代码之后立即使用 connection.commit() 或 connection.rollback()。
题:
如何在不重新创建表的情况下修复此错误,例如命令“select setval('foo_id_seq', 1)”?在我尝试使用“reindex table foo;”之前 来自 postgres 但不起作用,从 psql 运行提交或回滚也不起作用(可能连接 ID 不同)。也搜索谷歌重置所有交易数据或使用搜索键我上面的标题,但没有找到任何解决方案。
任何人都可以帮助我或告诉我解决这个问题的方向?
谢谢你。
编辑:
抱歉,也许这清楚地说明了我的问题:
create table foo(
foo_id serial unique not null primary key,
foo_column character(35) unique not null
);
Run Code Online (Sandbox Code Playgroud)
我从我的编程代码中使用这个 sql 命令插入数据:
insert into foo(foo_column) values('my_email@test.com');
Run Code Online (Sandbox Code Playgroud)
起初我通过“select * from foo;”检查表中的数据,但没有数据插入。我再次通过刷新页面(cgi 应用程序)重新运行代码并收到该消息,然后我再次检查表中select * from foo;但没有插入任何内容。这是我第一次使用事务插入,在我使用 mysql 之前根本没有事务。
我试图找到解决方案,但总是发现解决方案是针对列串行/大串行主键的,我很好奇所以我在这里问。有没有什么方法可以在不重新创建表的情况下解决这个错误?
希望这能让您更清楚地了解我的问题并感谢。