55 votes
Accepted

What's the best practice for upgrading a versioned Craft site?

I know your method works flawlessly, but it scares the crap out of me. Luckily Craft's update setup is magical. What I do is this. Make sure my repo is clear of unstaged files, just so the update ...
user avatar
49 votes
Accepted

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

My general approach for this, not just with Craft, but with all CMSes is to have a shared database for development. It's not the most ideal solution, since there can be overwriting of work, but it at ...
user avatar
18 votes

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

Hmm. I started out having a feeling existing tools might be a best approach here. I soon found that even with the better of these, except for in-dev patching, we may want to wait for a Craft ...
user avatar
  • 1,697
15 votes

What's the best practice for upgrading a versioned Craft site?

I actually keep all the craft system files gitignored. This way, all the assets are independent of the version of Craft and therefore of the updates. When it's time to run an update, I'll do it on dev ...
user avatar
  • 1,369
14 votes
Accepted

How to profile Craft CMS

Yup! Just turn on devMode in your general config: return array( 'devMode' => true, ); And then just open up a console (Firebug, Chrome, etc) and look in the profiling summary report.
user avatar
  • 1,828
13 votes
Accepted

Manual update without database backup

It is indeed possible. Craft has a handy general configuration option for this exact situation. return array( 'backupDbOnUpdate' => false ); Just add that to config/general.php and that ...
user avatar
13 votes

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

Note: This method is not for the faint of heart and might not be for everybody, but can be useful in some situations. One thing we do (at Airtype Studio, where I work) for larger installations is set ...
user avatar
  • 630
12 votes

How can I use multi-environment configuration to set each root URL?

Make sure to change the "Site URL" setting to {siteUrl} in your control panel settings... Control Panel > Settings > General > "Site URL" Within your config file, you'll also want to put your ...
user avatar
  • 23.6k
11 votes

What's the best practice for upgrading a versioned Craft site?

I personally use a slightly different method than what Jeremy recommends. Clean repo on the git side of things: no unstaged or non committed files Backup live DB and import in dev Update dev (test) ...
user avatar
10 votes
Accepted

Cannot connect to database with credentials provided in db.php

Move the check the SERVER_NAME switch up above the require_once $path;. You need to set CRAFT_ENVIRONMENT earlier.
user avatar
10 votes

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

I work with git for all my projects, I had to spend some time figuring out how to set up the folders and files, i.e.: what to gitignore. But it now works pretty well. All the core files are ...
user avatar
  • 1,369
10 votes
Accepted

Migrating a whole website between Craft instances

Make sure both Craft installs are up-to-date. Craft's license is saved in craft/config/license.key, make a backup of your purchased license file. Move all your files/directories except: /craft/app/ ...
user avatar
  • 8,316
10 votes
Accepted

Export database from control panel or Sequel Pro? What's the difference?

The difference in both size and speed is likely because Sequel Pro (and any other MySQL client) is likely using mysqldump, which is a native CLI command and highly optimized. Craft can't rely on ...
user avatar
  • 66.4k
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;
user avatar
9 votes

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

We currently handle this with database dumps from dev and taking screenshots of config screens and attaching them to git pull requests. There needs to be a better way though. The only CMS that has ...
user avatar
  • 806
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 ...
user avatar
9 votes
Accepted

craft_searchindex table keeps crashing

TL/DR: MySQL is horrible. The craft_searchindex table is the only table that uses MySQL's older MyISAM storage engine, instead of InnoDB (like the rest of the tables), because InnoDB didn't add ...
user avatar
  • 66.4k
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', '...
user avatar
8 votes
Accepted

Is it safe to mass delete users from the database directly

If you want to delete users (or any other elements in Craft) directly from the database, the place to do that is the elements table. Delete the row(s) from there, and all the elements’ rows in the ...
user avatar
8 votes

Does Craft Support MariaDB?

Update: Craft 3 officially supports MariaDB 5.5+ now. https://docs.craftcms.com/v3/requirements.html Not officially, no. MariaDB is supposed to a "drop-in" replacement for MySQL, but there are ...
user avatar
  • 66.4k
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 ...
user avatar
  • 66.4k
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 ...
user avatar
  • 66.4k
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, '...
user avatar
  • 66.4k
7 votes

Is there a way to delete all entries in a section?

If you delete the section, that will delete all the entries in the section as well.
user avatar
7 votes
Accepted

Using a plugin, how can I manipulate entry data?

You are correct in stating that Records typically define a new custom table for your plugin. However, don't forget that Craft already comes with many pre-existing Records. Take a look inside this ...
user avatar
  • 23.6k
7 votes

PHP Fatal error: Allowed memory size of X bytes exhausted

Craft will run out-of-the-box with 32M of memory, no problem. However, memory consumption will start to increase depending on several factors including: The complexity of your site, including the ...
user avatar
  • 66.4k
7 votes

How to clear the database of unused fields?

You can get the fields that aren’t in use anywhere by running this SQL query: SELECT f.* FROM craft_fields f LEFT JOIN craft_fieldlayoutfields l ON l.fieldId = f.id WHERE l.id IS NULL The easiest ...
user avatar
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
user avatar
  • 2,824
7 votes
Accepted

Move entry from one structure to another with parenting

That’s a little more complicated, and at that point you’re going to be best off writing your own PHP code to do it. Craft has a bootstrap file that makes it very easy to write custom PHP code without ...
user avatar
7 votes
Accepted

Why am I getting only one result with "craft()->db->createCommand()"?

Completely untested but it looks like you're just querying a row instead of all. Update queryRow() to queryAll()
user avatar
  • 1,828

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