Questions tagged [database]
Drupal provides a standard, vendor-agnostic abstraction layer for accessing database servers.
3,115
questions
0
votes
2
answers
27
views
How can I get the record of the last insert?
Is there a method to be called that will get the ID of the record just inserted?
In my module the first thing done is the insert of some data into a table.
After that I have other things to do in the ...
1
vote
1
answer
34
views
PDOStatement::execute(): SSL: Broken pipe
I have a Drupal 9.5.11 site running well on a single EC2 instance and a remote MySQL server (RDS). I am trying to replicate a very similar scenario with a single EC2 instance but I am using AWS ...
0
votes
0
answers
25
views
Unable to add Menu Items due to IntegrityConstraintViolationException
Background
I recently encountered an error when I try to create a new menu item:
Drupal\Core\Entity\EntityStorageException: SQLSTATE[HY000]: General error: 1364 Field 'parent' doesn't have a default ...
-3
votes
0
answers
30
views
How to update/convert stored field value in webform database from am to pm in Drupal 10
I have a field in database with datatype as integer, in my custom module I had to convert the date to readable format in d/m/y, the value is inserted to a custom table field using strtotime(date('d/m/...
0
votes
1
answer
86
views
How to join the node table with the url_alias table in a dynamic query?
Joining the node table to the url_alias table requires CONCAT. Here is an example of how this can be done:
$results = $db->query("
SELECT
n.nid, n.title,
a.source, a.alias
FROM ...
0
votes
1
answer
24
views
How do I sort view results by query order?
In my twig I use {{ drupal_view('slider', 'block_1', '74,84,82' ) }}, how can I make sure the output of this view has the slides in that specific order?
Currently on D9. I've looked around but can't ...
3
votes
1
answer
73
views
Drupal::entityQuery add CASE to have NULL values displayed last
I want to sort some entities in ascending expiration date, but I want those without expiration date to be at the end. Is there a way to add a CASE expression like this to the Drupal::entityQuery?
$...
1
vote
1
answer
80
views
Finding all nodes not referenced by a menu
I see this question was asked for Drupal 7, but the menu_link table doesn't exist in Drupal 9.
Is there a SQL query for listing all nodes that are not assigned to a menu?
0
votes
1
answer
158
views
Multiple primary key defined When importing DB to Dev
I'm trying to update my D9 dev site database using my production database, but it keeps erroring out when it reaches to ALTER table section in the database.
This is the
ERROR 1068 (42000) at line ...
0
votes
0
answers
44
views
How do I switch from PostgreSQL to MySQL
I set up a website using Drupal 10 and PostgreSQL but due to a communication delay, I just found out from the server team that the database on the staging/live servers is MySQL and not PostgreSQL. I ...
0
votes
0
answers
20
views
MSSQL - How to get a list of documents from a node that is using a space and a view?
I have a list of documents that are associated with a node of type space. The space has a page with a view and filter to list documents only related to that node.
I'm trying to query the database to ...
1
vote
1
answer
58
views
Paragraph Entity Query returns too many results
I'm trying to find a paragraph that have a certain taxonomy term value and on a matching parent node. I tried the code below, but it always returns over 30 values, when really only one paragraph ...
0
votes
0
answers
24
views
How to change the default database driver to the SQLite option in profile installation?
I have two database driver options in the "database setup" step while installing a Drupal project from a custom profile. By default, the MySQL database is selected.
But I want it to choose ...
-1
votes
1
answer
64
views
Using common database for multiple developers in local environment gets slow
When use the common database to develop in local environment for multiple developers in one Drupal 9 project is getting too slow. This issue occurs on Drupal sites only, others (Wordpress, Laravel, ...
1
vote
1
answer
189
views
Can I use entityQuery() in a Drupal 10 site to query entities from a Drupal 7 database?
Can I use entityQuery() to query entities in a Drupal 7 table?
I know it's possible to change the active database and then use a dynamic query to access the database, but can I do that also with ...
0
votes
1
answer
47
views
Condition that deletes rows older than 30 days
How can I query a condition that deletes the rows with column Date older than the last 30 days in DBTNG format?
I have tried this, but it's wrong.
$connection = \Drupal::database();
$connection->...
0
votes
1
answer
24
views
DBTNG sentence that sums a column from all rows of a specific user and dpm the total
This is my table test_sum_expression with columns:
uid (int) Stores the UID of the user.
points (int) Stores a number.
I have this SQL sentence which SUMS all points from user with uid 1.
SELECT uid, ...
0
votes
1
answer
92
views
Database addExpression SUM: Call to a member function execute() on string
I need to get the sum of all points values of the user with uid 1 from the test_sum_expression table. But when I try to execute I get this message Error: Call to a member function execute() on string....
5
votes
0
answers
56
views
Prioritise condition in QueryInterface
I have an overview with a search field. The query should search on both the title and description, but I would want to show my results that have the search parameter in the title first in the list.
I ...
-2
votes
3
answers
81
views
Get the HTML content from the database [closed]
I have a copy of a Drupal 9 database from which I need to download all the pages.
I loaded the database in MySQL Workbench CE and connected to it via Python. There are many tables, but no views or ...
0
votes
1
answer
133
views
The specified database connection is not defined: default for Drupal drush
I have the following configurations for my Drupal site:
sites/mysite/settings.local.php
$databases['default']['default'] = array(
'database' => 'mydb',
'username' => 'root',
'password' =&...
1
vote
1
answer
88
views
Schema insert row only if primary key doesn't exist
I'm doing an exercise where I have a table called visit_counter with fields uid (primary key that stores the user id) and user_visit_count (sum of user's page visits). The purpose of the table is to ...
0
votes
1
answer
46
views
How to delete a no longer used custom bin table?
I'm testing the cacheAPI with a custom bin. Everything is working. On the other hand, while testing, I created a custom bin with a name that does not suit me.
cache.lorem_bin:
class: Drupal\Core\...
0
votes
0
answers
19
views
Special sorting requirement in views for a multi-value field: how to avoid duplicated result items
This is another attempt to solve Custom views filter plugin: filter over two fields of a custom entity where one of the fields is a multi value field in a seperate table
I have create a basefield (...
1
vote
1
answer
61
views
While upgrading from D6, update.php appears to expect the Drupal 7 version of the database array and it throws errors
Leaving settings.php in place (but writeable), per instructions 13 + 14 of major upgrade section of https://api.drupal.org/api/drupal/UPGRADE.txt/7.x , with the new D7 codebase but the old D6 DB, i ...
1
vote
2
answers
92
views
Custom views filter plugin: filter over two fields of a custom entity where one of the fields is a multi value field in a seperate table
I have a custom entity with two basefields of type "list_string": "role" and "additional_role". I need this as "role" is used for sorting the entities by a very ...
-2
votes
1
answer
76
views
How can i subscribe/unsubscribe to a simplenews newsletter programmatically?
I have the following code to set subscriptions to a simplenews newsletter on or off:
$user_load = User::load($userID_current);
$newsletter_subscriptions = [
'newsletter1' => 'on',
...
0
votes
0
answers
34
views
Auto increment value less than max uid on users table
I'm seeing these errors flooding my log file.
They come from commerce order complete pages - and some registration pages too.
Drupal\Core\Entity\EntityStorageException: SQLSTATE[23000]: Integrity ...
1
vote
0
answers
45
views
How to add groupBy option WITH ROLLUP
With Drupal 9.5.3, a group by like this:
$query->groupBy("myfieldname WITH ROLLUP");
will result in
(...) Drupal\Core\Database\DatabaseExceptionWrapper: SQLSTATE[42S22]: Column not ...
1
vote
0
answers
27
views
How can I find all the nodes that use a hierarchical vocabulary taxonomy term and reference a child term but not its parent term
I am using Drupal 7.
I have a content type "Public Resource" that uses a hierarchical vocabulary called "Resource Topics" that has up to 3 levels (parent->child->child of ...
4
votes
0
answers
134
views
How can I dynamically switch between two databases for ALL queries?
I need to copy some entities from one Drupal 9 database to different Drupal 9 database. I have searched and looked high and low, but none of the examples I have found work anywhere. I found no help on ...
0
votes
1
answer
44
views
How do I enable all error messages altering directly a database table?
When I try to log in on a site, I get a generic error, which doesn't help in understanding what exactly is going wrong.
I would like to enable the All messages, with backtrace information option shown ...
-1
votes
1
answer
1k
views
Unable to connect to database when launching a new Drupal site with Lando [closed]
I tried to set up a new local drupal9 site using Lando, but it is unable to connect to the database and I am getting the following error.
Failed to connect to your database server. The server reports ...
0
votes
1
answer
308
views
Database update doesn't work after update from 9.2 to 9.3
I have unfortunately not found anything that seems to solve my issue. My Google-fu may be defunct.
I have upgraded a Drupal site from 9.2 to 9.3. This works as expected with composer (I use drupal/...
0
votes
1
answer
42
views
How can I delete properly an old translation string?
I found an old string into locales_source table, like that:
The associated 8.5.3 version seems outdated.
I would like to understand the usefulness of the keep this data in my database ? How to clean ...
1
vote
1
answer
182
views
Migrating from D7 / MySQL 5.6 to D9 / MySQL 8
I've read the documentation of upgrading (migrating) from D7 to D9, but didn't see anything about how to handle
changing MySQL versions in the process.
My D7 instance is on MySQL 5.6, which is ...
0
votes
1
answer
215
views
How to get fields of a product type using a database dynamic query
So I currently have multiple different product types that have varying fields. I was able to fetch all products using EntityTypeManager the following way:
$productStorage = \Drupal::entityTypeManager()...
-2
votes
2
answers
197
views
SQL error in Module
I'm trying to query the database inside my module, but I get this error.
Drupal\Core\Database\DatabaseExceptionWrapper: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in ...
1
vote
0
answers
1k
views
Argument 2 passed to Symfony\Component\Routing\RouteCollection::add() must be an instance of Symfony\Component\Routing\Route, boolean given
Ubuntu 18.04.6
Apache2, Postgresql 10, Drupal 8.9.6, PHP 7.2.34 (most of the modules require these versions)
I've tried trouble shooting this problem for multiple weeks. I'm attempting to migrate a ...
0
votes
1
answer
111
views
How can I collaborate with multiple developers? [closed]
I am developing a website on Drupal with 2 other developers. What would be the best way to collaborate? We plan to work on different git branches and there will be a dev and production branch as well. ...
3
votes
2
answers
209
views
Where is it documented that fields included in the entity_keys are 'required' regardless of the required property value in the field definition?
I've created a custom entity. One of the fields I've added is an entity reference field that was created calling BaseFieldDefinition::setRequired(FALSE). When I installed my module and tried to add a ...
-4
votes
1
answer
153
views
Access denied in Drush but granted in GUI [closed]
I am trying to install Drupal on a CentOS based shared server environment (namecheap.com) with mysql, ssh and Composer.
I have created a database username and a database with the same name and a ...
1
vote
2
answers
488
views
How to display results database query in a custom block
This is my first post - so hello everyone :)
I am trying to write a custom module that displays a certain number of posts from a certain category. I need a few of these blocks to display posts from ...
0
votes
1
answer
382
views
Delete a custom field from node_field_data table
A custom module added a field to the node_field_data table. Deleting the field in a hook update like this:
function HOOK_update_N() {
Database::getConnection()->schema()->dropField('...
-3
votes
1
answer
69
views
How to change a text with one dynamic term in all nodes? [closed]
I have a core website, no contrib modules or themes are installed.
All my nodes, from several content types, start with the following text, which is written in WYSIWYG CKeditor.
The term X is used to ...
1
vote
0
answers
47
views
Multiple value field create duplicate results when using leftJoin
I have a query to the database for a specific content type. Everything is working as expected but when I add a leftJoin query on the field 'node__field_country' which is a taxonomy term reference ...
1
vote
0
answers
1k
views
I can't import the configuration on production servers [closed]
I am unable to uninstall the MySQL module. I can't import the configuration on production servers when I upgrade Drupal from 9.3.x to 9.4.x.
I get the following error.
The import failed due to the ...
4
votes
1
answer
288
views
Is it possible to have a nested SELECT in a WHERE clause using dynamic queries?
I need to execute this SQL query using dynamic queries.
WHERE (node_field_data.status = 1)
AND (node__field_document_places.entity_id IN (SELECT entity_id FROM node__field_document_places where ...
2
votes
3
answers
200
views
How to check if secondary database definition exists
Can anyone please help me on how to check if secondary database is set. If not throw an error.
I am currently defining database connection as below.
Database::getConnection('default', 'sqlite')
I am ...
0
votes
1
answer
27
views
Access FieldItem object from Widget
I have a custom FieldItem with a method doing a calculation on the field's values:
class MyFieldItem extends FieldItemBase {
...
public function getAmountInEuros() {
$amount = $this->get('...