I have a Drupal site that I'm trying to update to the latest version 8.6.8. The problem is when I run the command 'drush updatedb', I see this error in the console;
Failed: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '1-0-0-en' for key 'PRIMARY': INSERT INTO {taxonomy_term__parent} (bundle, entity_id, revision_id, langcode, [error]
delta, parent_target_id) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4,
:db_insert_placeholder_5), (:db_insert_placeholder_6, :db_insert_placeholder_7, :db_insert_placeholder_8, :db_insert_placeholder_9, :db_insert_placeholder_10, :db_insert_placeholder_11),
(:db_insert_placeholder_12, :db_insert_placeholder_13, :db_insert_placeholder_14, :db_insert_placeholder_15, :db_insert_placeholder_16, :db_insert_placeholder_17),
(:db_insert_placeholder_18, :db_insert_placeholder_19, :db_insert_placeholder_20, :db_insert_placeholder_21, :db_insert_placeholder_22, :db_insert_placeholder_23),
(:db_insert_placeholder_24, :db_insert_placeholder_25, :db_insert_placeholder_26, :db_insert_placeholder_27, :db_insert_placeholder_28, :db_insert_placeholder_29),
(:db_insert_placeholder_30, :db_insert_placeholder_31, :db_insert_placeholder_32, :db_insert_placeholder_33, :db_insert_placeholder_34, :db_insert_placeholder_35),
(:db_insert_placeholder_36, :db_insert_placeholder_37, :db_insert_placeholder_38, :db_insert_placeholder_39, :db_insert_placeholder_40, :db_insert_placeholder_41),
(:db_insert_placeholder_42, :db_insert_placeholder_43, :db_insert_placeholder_44, :db_insert_placeholder_45, :db_insert_placeholder_46, :db_insert_placeholder_47),
(:db_insert_placeholder_48, :db_insert_placeholder_49, :db_insert_placeholder_50, :db_insert_placeholder_51, :db_insert_placeholder_52, :db_insert_placeholder_53),
(:db_insert_placeholder_54, :db_insert_placeholder_55, :db_insert_placeholder_56, :db_insert_placeholder_57, :db_insert_placeholder_58, :db_insert_placeholder_59),
(:db_insert_placeholder_60, :db_insert_placeholder_61, :db_insert_placeholder_62, :db_insert_placeholder_63, :db_insert_placeholder_64, :db_insert_placeholder_65),
(:db_insert_placeholder_66, :db_insert_placeholder_67, :db_insert_placeholder_68, :db_insert_placeholder_69, :db_insert_placeholder_70, :db_insert_placeholder_71),
(:db_insert_placeholder_72, :db_insert_placeholder_73, :db_insert_placeholder_74, :db_insert_placeholder_75, :db_insert_placeholder_76, :db_insert_placeholder_77),
(:db_insert_placeholder_78, :db_insert_placeholder_79, :db_insert_placeholder_80, :db_insert_placeholder_81, :db_insert_placeholder_82, :db_insert_placeholder_83),
(:db_insert_placeholder_84, :db_insert_placeholder_85, :db_insert_placeholder_86, :db_insert_placeholder_87, :db_insert_placeholder_88, :db_insert_placeholder_89),
(:db_insert_placeholder_90, :db_insert_placeholder_91, :db_insert_placeholder_92, :db_insert_placeholder_93, :db_insert_placeholder_94, :db_insert_placeholder_95),
(:db_insert_placeholder_96, :db_insert_placeholder_97, :db_insert_placeholder_98, :db_insert_placeholder_99, :db_insert_placeholder_100, :db_insert_placeholder_101)
As a result of this, when I look at the Status Report in Drupal, it shows that there are still database updates outstanding;
Mismatched entity and/or field definitions
The following changes were detected in the entity type and field definitions.
Taxonomy term
The Taxonomy term entity type needs to be updated.
The Published field needs to be installed.
The issue is, I have no idea why this is happening as it's a site I have only recently taken control of from another developer.
Truncating the table 'taxonomy_term__parent' fixed this.
In order to apply Pending Schema Updates.
Try "drush updb" and then
Try running "drush entity-updates".
In a complex query, I have a subquery to count/summarize children:
->addSelect('(SELECT CONCAT(COUNT(c.id), \'|\', SUM(c.field1), \'|\', SUM(c.field2), \'|\', SUM(c.field3)) FROM App\Entity\Child c WHERE c.parent = p.id GROUP BY c.parent)')
This query worked perfectly until I upgraded to the new version of Symfony (4.2) and doctrine orm 2.6.1. I got the following error:
[Syntax Error] line 0, col 25: Error: Expected StateFieldPathExpression | string | InputParameter | FunctionsReturningStrings | AggregateExpression, got 'COUNT'
I tried to use CAST ... AS CHAR(25) but it doesn't work (got the same error).
Anyone can help me please?
Best regards,
Jonathan
Looks Like it is regression in doctrine StringPrimary parser function.
After looking at code I have made comment with my observation in issue related to this problem (while not entierly describing it).
Essentially new function missing this part, and defaulting to error when encountering any aggregate functions:
default:
if ($this->isAggregateFunction($lookaheadType)) {
return $this->AggregateExpression();
}
PS. link to the related issue:
https://github.com/doctrine/doctrine2/issues/7205
I found a workaround: I install doctrine extensions and I replace CONCAT by CONCAT_WS (DoctrineExtensions\Query\Mysql\ConcatWs).
Best regards
I'm trying to create database like this:
const QUERY_DB_CREATE = "
CREATE DATABASE :db_name
";
if (database is not exists) {
$stmt = $conn->prepare(self::QUERY_DB_CREATE);
$stmt->bindValue(':db_name', $db_name, 'string');
return $stmt->execute();
}
Error
PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "'testtesttest2'"
What am I doing wrong?
You should take a look at the DoctrineBundle command (for use in the Symfony framework) for creating databases. Without knowing more about your implementation details, these lines especially should be useful in your case:
$tmpConnection = DriverManager::getConnection($params);
...
$tmpConnection->getSchemaManager()->createDatabase($name);
I am using Doctrine 2 within ZF2 code and I am trying to write update query.
Code is like this:
$qb = $this->getEntityManager()->createQueryBuilder();
$qb->update('Application\Entity\Groups', 'group')
->set('group.state', '?1')
->set('group.modified', '?2')
->where($qb->expr()->eq('group.id', '?3'))
->setParameter(1, \Application\Entity\Groups::STATE_DELETED)
->setParameter(2, $modified)
->setParameter(3, $group_id);
Doctrine2 complains about query. Exact error message is:
(string) [Syntax Error] line 0, col 87: Error: Expected Literal, got 'group'
It seems that keyword group created problems. When I used gr alias instead of group it worked fine.
So, DQL bellow worked:
$qb = $this->getEntityManager()->createQueryBuilder();
$qb->update('Application\Entity\Groups', 'gr')
->set('gr.state', ':state')
->set('gr.modified', ':modified')
->where($qb->expr()->eq('gr.id', ':group_id'))
->setParameter('group_id', $group_id)
->setParameter('state', \Application\Entity\Groups::STATE_DELETED)
->setParameter('modified', $modified);
I have an entity Person with fields String name and String designation. When I tried to query using Eclipselink ExpressionBuilder, as:
Project project=new Project();
Login login=new DatabaseLogin();
login.setUserName("root");
login.setPassword("root");
project.setLogin(login);
DatabaseSession session=project.createDatabaseSession();
ExpressionBuilder expBuilder=new ExpressionBuilder();
Expression expression=expBuilder.get("name").equalsIgnoreCase("SomeName");
Vector readAllObjects = session.readAllObjects(Person.class, expression);
On executing last statement the following exception is thrown :
Exception [EclipseLink-6007] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.QueryException
Exception Description: Missing descriptor for [class com.mycompany.entity.Person].
Query: ReadAllQuery(referenceClass=Person)
What might be the reason? Thanks in advance...
At last I got it. Instead of DatabaseSession, org.eclipse.persistence.sessions.server.ClientSession had to be used.
JpaEntityManager jpaEntityManager=em.unwrap(JpaEntityManager.class);
ClientSession session=jpaEntityManager.getServerSession().acquireClientSession();
ExpressionBuilder expBuilder=new ExpressionBuilder();
Expression expression=expBuilder.get("name").equalsIgnoreCase("SomeName");
Vector readAllObjects = session.readAllObjects(Person.class, expression);
em is the EntityManager.
This solved the issue.
You did not add a descriptor for Person. You need to map it to be able to query it.
Also consider using JPA.