Skip to main content
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;
Ben Fleming's user avatar
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', '...
Robin Schambach's user avatar
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 ...
Brad Bell's user avatar
  • 67.5k
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, '...
Brad Bell's user avatar
  • 67.5k
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.
Brad Bell's user avatar
  • 67.5k
7 votes
Accepted

DB CPU running at 100%, Pages Never Load, Moving from MySQL to MariaDB

You're likely running into an issue seen with recent versions of MariaDB (10.6 and later), where importing an SQL dump can result in indexes not being created properly. Essentially, this will make ...
Mats Mikkel Rummelhoff's user avatar
6 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 ...
SteveO's user avatar
  • 336
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-...
HendrikEng's user avatar
  • 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/...
Crafty Cat's user avatar
6 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 ...
Brandon Kelly's user avatar
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 ...
andrew.welch's user avatar
  • 11.6k
5 votes

Query only returning 100 records at a time?

By default, Craft sets a limit of 100. Set it to null: limit(null).
awcross's user avatar
  • 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 ...
andrew.welch's user avatar
  • 11.6k
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 ...
Lindsey D's user avatar
  • 24k
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 ...
Brad Bell's user avatar
  • 67.5k
4 votes
Accepted

Entry slug auto appends -1 even when the original slug is unique

I don't know the specific rules Craft uses but I believe Craft auto appends the -1 when it tries to save an Element that has a matching URI in the craft_elements_i18n table. A few scenarios that I ...
Ben Parizek's user avatar
  • 13.5k
4 votes
Accepted

date in database -1 day as on frond-end

The database will be storing the date as seconds since 1970 (epoch) and your view on that is not localised. However, the front end date is localised for your time zone. Of this I am more sure than ...
Jeremy Daalder's user avatar
4 votes

Date value different in CP and database

Craft stores all dates in UTC to the database, no matter what timezone you configure in settings. When (user) models are populated, e.g. for use in the CP, DateTime objects are created from these ...
carlcs's user avatar
  • 36.3k
4 votes
Accepted

What is the best practice in Craft 3 to sync schema between environments?

With the release of Craft 3.1 you can now keep fields (and other things) in sync between multiple environments. Read more here: https://docs.craftcms.com/v3/project-config.html
Radmation's user avatar
  • 198
4 votes

Simple save data to db in Craft CMS

I suggest you to read about the Yii Query Builder craft()->db->createCommand() ->insert('mytablename', array( 'field1' => 'foo', 'field2' => 'bar' )); ...
Robin Schambach's user avatar
4 votes
Accepted

Craft 3 : What are the advantages to use PostgreSQL and when should I use it instead of MySQL?

This isn't actual first-hand experience talking, but from what I've read, Postgres will start to see gains when we're talking about very large data sets, either in terms of the size of the columns, or ...
andrew.welch's user avatar
  • 11.6k
4 votes
Accepted

Where are tags stored in the database?

Tags are Elements and are stored in multiple places in the database, so editing the db directly may not be as easy as just finding the Tags you want and deleting them. The tag itself is stored in ...
Ben Parizek's user avatar
  • 13.5k
4 votes
Accepted

Does Craft ActiveRecord require any special table column (dateUpdated, dateCreated,...)?

The only difference between Craft and Yii active records are the columns dateCreated, dateUpdated and uid if you have these columns you should extend Crafts ActiveRecord since it's save function adds ...
Robin Schambach's user avatar
4 votes
Accepted

Working locally after cloning Craft 3 from Hyperlane

Solved. The config/db.php cloned from Hyperlane refers to different env variable names than those used within my .env file. Changing the names in config/db.php solved the issue. Before: return [ ...
Clive Portman's user avatar
4 votes

How to host a huge website on Craft (10k pages, over a dozen languages, 2GB database)

"Digital Ocean through Forge" is a good solution. Sounds like you're on a well-powered droplet as well. I'd recommend moving your assets into the cloud to speed things up a bit. Something like Amazon ...
Lindsey D's user avatar
  • 24k
4 votes

Getting column not found when using 'Entry::find()' to find the matching channel entry in custom plugin

All custom fields get the field_ prefix and a pseudo-random suffix like _ywsmdgzc for their column name in the database. If you want to use custom conditions in a query, you need to include both. To ...
MoritzLost's user avatar
  • 11.6k
3 votes

MSSQL Support for Craft?

Assuming you're running Craft CMS 3, the Connect plugin will let you connect to MSSQL databases (local or remote) You'll just need to do: composer require yiisoft/yii2-mssql ...on your Craft CMS ...
andrew.welch's user avatar
  • 11.6k
3 votes

Craft CMS Backup DB

The assets themselves are not included in the backup. But if you have added assets into those directories, the paths to them are saved in the database and will therefore be included in the backup.
awcross's user avatar
  • 99
3 votes

Craft CMS Backup DB

The database backup will only backup the tables within your database, which does include references to your assets; such as their title, filename etc. However, the asset files themselves will not be ...
Scott Wakefield's user avatar
3 votes

Staging Server Database Not Connecting

It looks as if you've sorted thing out (dev.nec... vs nec.dev...) In general, I find the domain name matching in the config files to be confusing and error prone. I always follow the advice in the ...
Marion Newlevant's user avatar

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