本文介绍了手动插入joomla数据库时,键"idx_client_id_parent_id_alias_language"的重复条目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Joomla 3

我正在尝试将一些记录手动插入到#__menu中.因为对于大多数字段,我只能使用其他记录所具有的值,所以我试图从现有记录中获取stdObject并将其插入回表中.在此之前,我需要注意可能的重复密钥.我阅读了表结构,除了id之外,我发现字段lftrgt似乎必须是唯一的.因此,以下是我尝试的方法:

I am trying to manually insert some records into #__menu. Since for most fields I can just use the value that other records have, I am trying to get a stdObject from an existing record and insert it back to the table. Before that, I need to take care of the possible key duplicate. I read the table structure, and besides id, I find field lft and rgt seem to have to be unique. So the following is what I try:

$db = JFactory::getDbo();
$query = $db->getQuery(true);
$sql = 'SELECT * FROM `#__menu` WHERE id = 203';
$db->setQuery($sql);
$example = $db->loadObjectList()[0];
unset($example->id);                     
unset($example->lft);
unset($example->rgt);

$db->insertObject('#__menu',$example);

我收到的错误消息是

SQL =插入到#__menu (menutypetitlealiasnotepathlinktypepublishedparent_idlevelcomponent_idchecked_outchecked_out_timebrowserNavaccessimgtemplate_style_idparamshomelanguageclient_id) 值('隐藏','测试','001','','001','index.php?option = com_k2& view = item& layout = item& id = 1','component','1' ,'1','1','10125','0','0000-00-00 00:00:00','0','1',' ','0','{\"menu-anchor_title \":\"\",\"menu-anchor_css \":\"\",\"menu_image \":\"\",\"menu_text \" :1,\"menu_show \":1,\"page_title \":\"\",\"show_page_heading \":\"\",\"page_heading \":\"\",\"pageclass_sfx \": \"\",\"menu-meta_description \":\"\",\"menu-meta_keywords \":\"\",\"robots \":\"\",\"secure \":0} ','0','*','0')

SQL=INSERT INTO #__menu (menutype,title,alias,note,path,link,type,published,parent_id,level,component_id,checked_out,checked_out_time,browserNav,access,img,template_style_id,params,home,language,client_id) VALUES ('hidden','test','001','','001','index.php?option=com_k2&view=item&layout=item&id=1','component','1','1','1','10125','0','0000-00-00 00:00:00','0','1',' ','0','{\"menu-anchor_title\":\"\",\"menu-anchor_css\":\"\",\"menu_image\":\"\",\"menu_text\":1,\"menu_show\":1,\"page_title\":\"\",\"show_page_heading\":\"\",\"page_heading\":\"\",\"pageclass_sfx\":\"\",\"menu-meta_description\":\"\",\"menu-meta_keywords\":\"\",\"robots\":\"\",\"secure\":0}','0','*','0')

我不明白为什么会有一个名为"idx_client_id_parent_id_alias_language"的键,它肯定不是表的字段之一.谷歌搜索返回一些结果,但在我看来,这些都与我的问题无关.

I don't understand why there is a key called 'idx_client_id_parent_id_alias_language', it sure is not one of the table's fields. Googling it returns some result, but it seems to me none of them is related to my problem.

推荐答案

我想写一个答案,因为shenkwen评论说他用谷歌搜索了答案,但没有发现任何帮助.

Thought that I would write up an answer as shenkwen commented that he googled for an answer and found nothing helpful.

OP看到的错误是由他手动插入一行引起的,但是菜单表上有一个多列键.密钥是 client_id parent_id alias language 的组合.

The error that OP is seeing as caused by him manually inserting a row but there is a multiple column key on the menu table. The key is a combination of client_id, parent_id, alias and language.

您不能有两个共享相同值的行.如OP的评论所述,他正在复制别名.

You can not have two rows which share those same values. As noted in the comments from OP he was duplicating the alias.

这篇关于手动插入joomla数据库时,键"idx_client_id_parent_id_alias_language"的重复条目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 06:04