10 votes
Accepted

Query only returning 100 records at a time?

Craft imposes a default limit of 100 for element queries. To disable this you need to specify a limit of null. $criteria->limit = null;
9 votes

What's the best practice for handling data migration and organization across development environments?

I found a great blog post where the author uses Phinx and MySQL Query Log to create database migrations. I summarized its content into 10 easy steps: Step 1 Enable the MySQL Query Log on your dev ...
9 votes
Accepted

Craft 3: Get Data from a custom Table via createCommand()

You can use either an activeRecord for it $customer = Customer::find() ->where(['id' => 123]) ->one(); Or a query $rows = (new \craft\db\Query()) ->select(['id', '...
8 votes
Accepted

Query table in a different database

Have you tried it? I'm pretty sure that's not going to work as Active Record is tied to the db connection in craft/config/db.php hanging off of craft()->db. You should be able to pull it off with ...
  • 67k
8 votes
Accepted

Craft 3: Can't backup database ("mysqldump: command not found")

Craft 3 did away with the PHP-based database backup solution that Craft 2 utilized (for many reasons). Now it requires that the mysqldump executable (if you're using MySQL) or pg_dump executable (if ...
  • 67k
8 votes

Accessing Multiple Databases in Craft

From your config/app.php file you could do something like this: return [ 'components' => [ 'otherDb' => [ 'class' => craft\db\Connection::class, '...
  • 67k
7 votes

"Eager loading" of relations like Yii's "with" function

This feature has now made it into Craft core as of version 2.6. See this link for documentation on the subject: https://craftcms.com/docs/templating/eager-loading-elements
  • 2,834
7 votes
Accepted

How do I build a LIKE query with DbCommand/Query Builder?

Just before posting the question, I had the good mind to read the Yii CDbCommand docs again, and I figured this out myself: $query->orWhere(array( 'like', 'somecolumn', '%foo%' ));
7 votes
Accepted

Craft 3: Update database after CMS upgrade via console command

You can use Yii's migrate console command. Triggered in Craft 3 via craft migrate --type=app.
  • 67k
6 votes

"Eager loading" of relations like Yii's "with" function

I've been thinking about ways to achieve this recently, and I've put together a basic proof-of-concept plugin for fetching one level of relations for a collection of elements, with no more than two ...
  • 4,381
6 votes

Updated Information Requested | Craft CMS & MariaDB

We currently have no open tickets or known issues with MariaDB. Fun fact: according to our logs roughly 15% of Craft installs are running some version of MariaDB.
  • 67k
6 votes

How many entries could the Craft database hold before it slows down?

It's a bit of a loaded question, but generally it's going to depend more on environmental limitations than anything with Craft itself. If you're on a shared host along with 200 other accounts using ...
  • 67k
6 votes
Accepted

Good practice to "Clear Caches" before you "Backup Database"?

Is this helpful, or am I just being OCD? Completely OCD. :) The database backup class already excludes unnecessary tables like asset indexing data, sessions, template caches, etc. during a backup. ...
  • 67k
6 votes
Accepted

Many db requests with relationship fields

This is how relationships work in Craft at the moment. Each relation equals +1 query. If you don't access your relation on an entry the query isn't executed. So by only fetching title and/or id you ...
  • 2,834
6 votes
Accepted

Deploying CraftCMS to Digital Ocean

I would suggest to read through the following articles: https://nystudio107.com/blog/multi-environment-config-for-craft-cms https://nystudio107.com/blog/database-asset-syncing-between-environments-...
  • 1,064
6 votes

Craft 3 cannot find mysqldump command, console works

After a lot of digging I found an SO post which recommended updating the environment variable via PHP: putenv("PATH={$_SERVER["PATH"]}:/usr/local/mysql/bin"); Adding that line into craft/config/...
5 votes

What's the best practice for handling data migration and organization across development environments?

I'm currently implementing a workflow that's very efficient for us. The trick is to use Backup Pro to "backup" locally and then "restore" once the site is deployed. This essentially version controls ...
  • 326
5 votes
Accepted

When does Craft change or delete template caches?

Craft can delete caches in a few different ways: When somebody manually clears the cache via Settings->Clear Caches When Elements within {% cache %} tag are saved or deleted When a new Element is ...
  • 13.3k
5 votes

Populating craft database from non-craft data

Brad is absolutely correct. Better off trying for an existing plugin (we have one in the works over here for very robust Wordpress migrating!!!), but here are a few steps to get you started: Move the ...
5 votes
Accepted

Moving to another database: "Specified key was too long"

I bumped into this last week, and it is exactly as you suspect... your new database does not support InnoDB, which is a requirement of Craft. I'd suggest discussing the matter with your hosting ...
  • 23.8k
5 votes

Get related entry data within a plugin (ElementCriteriaModel) without extra queries

I fixed this now by using the method buildElementsQuery, like so: $query = craft()->elements->buildElementsQuery($criteria, $contentTable, $fieldColumns); After that, I was able to add ...
5 votes
Accepted

Updating the Database for plugin settings

You don't need to create Records, Models or interact with the database to store your plugin settings – Craft handles this for you out of the box. Here's how: In your main plugin file (...
5 votes

Entries as Flat Files

Short answer; no. Craft uses a database to store and query for content and doesn't have any way to work with content in files the way that Statamic has. But, migrating the content into Craft's ...
  • 7,258
5 votes
Accepted

Migration of Craft CMS from one host to another

You need a copy of the database which you can either export via Craft's Control Panel or via phpMyAdmin or a similar database management tool. You need these folders: craft/templates craft/...
  • 428
5 votes

Migration of Craft CMS from one host to another

The accepted answer is a good one, but I thought I'd add something as food for thought. If you set up your workflow such that: All of your Craft CMS project is checked into a git repo and deploy it ...
  • 11.3k
5 votes

Query only returning 100 records at a time?

By default, Craft sets a limit of 100. Set it to null: limit(null).
  • 99
5 votes

Craft can't connect to the database (using ec2)

So a couple of things: It's probably not a great idea to connect as root -- it'd be better to create a mysql user that has access only to that db. Make sure that the db you're connecting to is indeed ...
  • 11.3k
5 votes

Self-hosting requirements/scaling

No reason at all, that should work perfectly fine. In fact, at least 90% of my projects keep files, database, and assets all on the same server. For the remaining 10%, I'm usually only moving the ...
  • 23.8k
5 votes

Randomly getting the "Integrity constraint violation" sql error on saving entry

It's not a Craft bug. The error means that the data in your craft_relations table is out of sync with the data in the your craft_elements table. i.e. an ID exists in craft_relations.targetId that ...
  • 67k
5 votes
Accepted

Is there a name for Craft 3's database model?

Craft uses a fairly typical relational model, where most1 custom fields have a single column in the content table, set to an appropriate column type chosen by the field type. Unlike EAV, which crams ...

Only top scored, non community-wiki answers of a minimum length are eligible