I have somehow managed to duplicate some fields in my Craft install (see image of unused fields). When I delete the unused duplicates I create a server error and can't access Craft.
To rectify I had to switch on and off my DigitalOcean droplet to get the server working again and reinstall a database backup. I want to remove the duplicates safely. How do I do this without bringing down the whole website?
It would also be good to know any theories to why this happened in the first place so I can rectify.
Update 1
I deleted a field on my local version and have outputted the databased error below.
Thanks in advance.
Database Error when deleting field on local version:
Database Exception – yii\db\Exception
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'content.field_projectDescription' in 'field list'
The SQL being executed was: SELECT `users`.`password`, `elements`.`id`, `elements`.`fieldLayoutId`, `elements`.`uid`, `elements`.`enabled`, `elements`.`archived`, `elements`.`dateCreated`, `elements`.`dateUpdated`, `elements_sites`.`id` AS `siteSettingsId`, `elements_sites`.`slug`, `elements_sites`.`siteId`, `elements_sites`.`uri`, `elements_sites`.`enabled` AS `enabledForSite`, `users`.`username`, `users`.`firstName`, `users`.`lastName`, `users`.`email`, `users`.`unverifiedEmail`, `users`.`admin`, `users`.`locked`, `users`.`pending`, `users`.`suspended`, `users`.`lastLoginDate`, `users`.`lockoutDate`, `users`.`photoId`, `users`.`hasDashboard`, `content`.`id` AS `contentId`, `content`.`field_jobNotes`, `content`.`field_announcementBanner`, `content`.`field_announcementColor`, `content`.`field_announcementLink`, `content`.`field_announcementText`, `content`.`field_personBiography`, `content`.`field_careersForm`, `content`.`field_caseStudyClientName`, `content`.`field_caseStudyClientQuote`, `content`.`field_caseStudyClientAttribution`, `content`.`field_caseStudyUrl`, `content`.`field_eventEndDate`, `content`.`field_eventCost`, `content`.`field_eventHosted`, `content`.`field_eventLocation`, `content`.`field_eventUrl`, `content`.`field_expertOpinion`, `content`.`field_featured`, `content`.`field_fundDescription`, `content`.`field_fundUrl`, `content`.`field_fundingOpportunityAim`, `content`.`field_fundingOpportunityCurrency`, `content`.`field_fundingOpportunityDescription`, `content`.`field_fundingOpportunityFunder`, `content`.`field_fundingOpportunityFundingType`, `content`.`field_fundingOpportunityLimit`, `content`.`field_fundingOpportunityProjectStartDate`, `content`.`field_fundingOpportunityResultDate`, `content`.`field_fundingOpportunityScope`, `content`.`field_fundingOpportunityShowStartDate`, `content`.`field_fundingOpportunitySubmissionDate`, `content`.`field_fundingOpportunityURL`, `content`.`field_fundingOpportunityValue`, `content`.`field_headOffice`, `content`.`field_globalHeaderMeta`, `content`.`field_heading`, `content`.`field_hidden`, `content`.`field_imageVariants16by9`, `content`.`field_imageVariants16by9Parallax`, `content`.`field_imageVariantsThumb`, `content`.`field_innovationIntegratorAssetRef`, `content`.`field_intro`, `content`.`field_investorInsight`, `content`.`field_jobApplicationId`, `content`.`field_jobApplicationType`, `content`.`field_jobEligibilityNotice`, `content`.`field_jobReferenceNo`, `content`.`field_jobSalary`, `content`.`field_personJobTitle`, `content`.`field_latitude`, `content`.`field_linkedInProfile`, `content`.`field_locationAddress`, `content`.`field_locationPhone`, `content`.`field_logoVariants`, `content`.`field_longitude`, `content`.`field_mapLocation`, `content`.`field_partnerDescription`, `content`.`field_partnerUrl`, `content`.`field_personPostNominals`, `content`.`field_previewDescription`, `content`.`field_projectDescription`, `content`.`field_projectEndDate`, `content`.`field_projectNo`, `content`.`field_projectRegion`, `content`.`field_projectStartDate`, `content`.`field_projectUrl`, `content`.`field_seoSettings`, `content`.`field_eventStartDate`, `content`.`field_subtitle`, `content`.`field_taxonomyName`, `content`.`field_caseStudyChallenge`, `content`.`field_caseStudyOutcome`, `content`.`field_jobPerson`, `content`.`field_jobRole`, `content`.`field_thoughtLeadershipCampaign`, `content`.`field_timelineText`, `content`.`field_timelineUrl`, `content`.`field_timelineYear`, `content`.`field_personTitle`
FROM (SELECT `elements`.`id` AS `elementsId`, `elements_sites`.`id` AS `elementsSitesId`, `content`.`id` AS `contentId`
FROM `elements` `elements`
INNER JOIN `users` `users` ON `users`.`id` = `elements`.`id`
INNER JOIN `elements_sites` `elements_sites` ON `elements_sites`.`elementId` = `elements`.`id`
INNER JOIN `content` `content` ON `content`.`elementId` = `elements`.`id`
WHERE (`elements`.`id`=1) AND (`elements`.`archived`=FALSE) AND (`elements`.`dateDeleted` IS NULL) AND (`elements`.`draftId` IS NULL) AND (`elements`.`revisionId` IS NULL)
ORDER BY `users`.`username`
LIMIT 1) `subquery`
INNER JOIN `users` `users` ON `users`.`id` = `subquery`.`elementsId`
INNER JOIN `elements` `elements` ON `elements`.`id` = `subquery`.`elementsId`
INNER JOIN `elements_sites` `elements_sites` ON `elements_sites`.`id` = `subquery`.`elementsSitesId`
INNER JOIN `content` `content` ON `content`.`id` = `subquery`.`contentId`
ORDER BY `users`.`username`
Error Info: Array
(
[0] => 42S22
[1] => 1054
[2] => Unknown column 'content.field_projectDescription' in 'field list'
)
↵
Caused by: PDOException
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'content.field_projectDescription' in 'field list'
in /Users/danlee/Sites/Work/galileo/vendor/yiisoft/yii2/db/Command.php at line 1293
Interface showing duplicated fields
Update 2:
I get the following output when running ./craft migrate/all
. The odd thing is I can connect to the database fine and edit content without issue.
Craft can’t connect to the database. Check your connection settings.
Yii Migration Tool (based on Yii v2.0.38)
Exception 'craft\errors\DbConnectException' with message 'Craft CMS can’t connect to the database with the credentials in config/db.php.'
in /Users/danlee/Sites/Work/galileo/vendor/craftcms/cms/src/db/Connection.php:173
Caused by: Exception 'yii\db\Exception' with message 'SQLSTATE[HY000] [2002] No such file or directory'
in /Users/danlee/Sites/Work/galileo/vendor/yiisoft/yii2/db/Connection.php:642
Caused by: Exception 'PDOException' with message 'SQLSTATE[HY000] [2002] No such file or directory'
in /Users/danlee/Sites/Work/galileo/vendor/yiisoft/yii2/db/Connection.php:710
db.config file
<?php
/**
* Craft 3 Multi-Environment
* Efficient and flexible multi-environment config for Craft 3 CMS
*
* $_ENV constants are loaded by craft3-multi-environment from .env.php via
* ./web/index.php for web requests, and ./craft for console requests
*
* @author nystudio107
* @copyright Copyright (c) 2017 nystudio107
* @link https://nystudio107.com/
* @package craft3-multi-environment
* @since 1.0.5
* @license MIT
*/
/**
* Database Configuration
*
* All of your system's database configuration settings go in here.
* You can see a list of the default settings in src/config/DbConfig.php
*/
return [
// All environments
'*' => [
'database' => getenv('CRAFTENV_DB_DATABASE'),
'driver' => getenv('CRAFTENV_DB_DRIVER'),
'server' => getenv('CRAFTENV_DB_SERVER'),
'user' => getenv('CRAFTENV_DB_USER'),
'password' => getenv('CRAFTENV_DB_PASSWORD'),
'schema' => getenv('CRAFTENV_DB_SCHEMA'),
'tablePrefix' => getenv('CRAFTENV_DB_TABLE_PREFIX'),
'port' => getenv('CRAFTENV_DB_PORT'),
],
// Live (production) environment
'live' => [
],
// Staging (pre-production) environment
'staging' => [
],
// Local (development) environment
'local' => [
],
];
env.php file
<?php
/**
* Craft 3 Multi-Environment
* Efficient and flexible multi-environment config for Craft 3 CMS
*
* @author nystudio107
* @copyright Copyright (c) 2017 nystudio107
* @link https://nystudio107.com/
* @package craft3-multi-environment
* @since 1.0.5
* @license MIT
*
* This file should be renamed to '.env.php' and it should reside in your root
* project directory. Add '/.env.php' to your .gitignore. See below for production
* usage notes.
*/
// Determine the incoming protocol
if (isset($_SERVER['HTTPS']) && (strcasecmp($_SERVER['HTTPS'], 'on') === 0 || $_SERVER['HTTPS'] == 1)
|| isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && strcasecmp($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') === 0
) {
$protocol = "https://";
} else {
$protocol = "http://";
}
// Determine the server hostname
$httpHost = $_SERVER['HTTP_HOST'] ?? '';
// The $craftEnvVars are all auto-prefixed with CRAFTENV_ -- you can add
// whatever you want here and access them via getenv() using the prefixed name
$craftEnvVars = [
// The Craft environment we're running in ('local', 'staging', 'live', etc.).
'CRAFT_ENVIRONMENT' => 'local',
// The database driver that will used ('mysql' or 'pgsql')
'DB_DRIVER' => 'mysql',
// The database server name or IP address (usually this is 'localhost' or '127.0.0.1') // 185.119.174.157
'DB_SERVER' => 'localhost',
// The database username to connect with // einstein_cpi
'DB_USER' => 'xxxx',
// The database password to connect with // Market!ng123+
'DB_PASSWORD' => 'xxxx',
// The name of the database to select // einstein_franklin
'DB_DATABASE' => 'xxxx',
// The database schema that will be used (PostgreSQL only, usually 'public')
'DB_SCHEMA' => 'public',
// The prefix that should be added to generated table names (usually '', it's only necessary
// if multiple things are sharing the same database)
'DB_TABLE_PREFIX' => '',
// The port to connect to the database with. Default ports are 3306 for MySQL and 5432 for PostgreSQL.
'DB_PORT' => '3306',
// The secure key Craft will use for hashing and encrypting data, see:
// https://craftcms.com/docs/config-settings#validationKey
'SECURITY_KEY' => 'xxxx',
// The site url to use; it can be hard-coded as well
'SITE_URL' => $protocol . $httpHost . '/',
// The base url environmentVariable to use for Assets; it can be hard-coded as well
// You will also need to configure `config/volumes.php` for your Asset Volumes
'BASE_URL' => $protocol . $httpHost . '/',
// The base path environmentVariable for Assets; it can be hard-coded as well
// You will also need to configure `config/volumes.php` for your Asset Volumes
'BASE_PATH' => realpath(dirname(__FILE__)) . '/web/content/',
// The AWS API key with read/write access to Spaces
'SPACES_API_KEY' => 'xxxx',
// The AWS API key secret
'SPACES_SECRET' => 'xxxx',
// The region the S3 bucket is in
'SPACES_ENDPOINT' => 'xxxx',
// The region the S3 bucket is in
'SPACES_REGION' => 'xxxx',
// The name of the S3 bucket
'SPACES_BUCKET' => 'xxxx',
// The url of the S3 bucket
'SPACES_URL' => 'xxxx',
// Backblaze Settings
'BACKBLAZE_B2_MASTER_KEY_ID' => 'xxxx',
'BACKBLAZE_B2_MASTER_APP_KEY' => 'xxxx',
'BACKBLAZE_B2_BUCKET_REGION' => 'xxxx',
'BACKBLAZE_B2_BUCKET_NAME' => 'xxxx',
'BACKBLAZE_B2_BUCKET_BACKUP_PREFIX' => 'xxxx',
'BACKBLAZE_B2_BUCKET_SYNC_PREFIX' => 'xxxx',
];
// Set all of the .env values, auto-prefixed with `CRAFTENV_`
foreach ($craftEnvVars as $key => $value) {
putenv("CRAFTENV_{$key}={$value}");
}