<p>You should be able to use:</p>
<pre class="lang-bash prettyprint-override"><code>php craft migrate/mark
</code></pre>
<p>...to update the DB to tell it that the migration has actually already been run.</p>
<p>In your specific case, that would be:</p>
<pre class="lang-bash prettyprint-override"><code>php craft migrate/mark m230710_162700_element_activity
</code></pre>
<p>ref: <a href="https://www.yiiframework.com/doc/guide/2.0/en/db-migrations#modifying-migration-history" rel="nofollow noreferrer">https://www.yiiframework.com/doc/guide/2.0/en/db-migrations#modifying-migration-history</a></p>
<p>That's <strong>assuming</strong> this migration is one that Craft created. If it's a migration that the Campaign plugin created, do:</p>
<pre class="lang-bash prettyprint-override"><code>php craft migrate/mark --plugin=campaign m230710_162700_element_activity
</code></pre>
<p>...so that it knows to look for the migration from that specific plugin, rather than looking for the migration from Craft.</p>
<p>ref: <a href="https://craftcms.com/docs/4.x/console-commands.html#migrate-mark" rel="nofollow noreferrer">https://craftcms.com/docs/4.x/console-commands.html#migrate-mark</a></p>
<p>&quot;The command will modify the migration table by adding or deleting certain rows to indicate that the database has been applied migrations to the specified one. No migrations will be applied or reverted by this command.&quot;</p>

CC BY-SA 4.0
2023-12-07T19:14:40.757Z
2023-12-07T19:25:53.997Z
2023-12-07T19:25:53.997Z
andrew.welch
<p>I'm stuck in a &quot;migration&quot; that is trying to install a table which it clearly didn't check for (because yes, it is quite already there.)</p>
<p>When I remove the table and allow the migration to go through, Campaign blows up.</p>
<p>Craft is on 4.5.4</p>
<p>Question: how do I get around this? Get past this?</p>
<p>One of Craft CMS’s migrations failed.</p>
<pre><code>Database Exception: SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'craft_elementactivity' already exists
The SQL being executed was: CREATE TABLE craft_elementactivity (
elementId int(11) NOT NULL,
userId int(11) NOT NULL,
siteId int(11) NOT NULL,
draftId int(11) NULL DEFAULT NULL,
type varchar(255) NOT NULL,
timestamp datetime(0),
PRIMARY KEY(elementId, userId, type)
) ENGINE = InnoDb DEFAULT CHARACTER SET = utf8

Migration: craft\migrations\m230710_162700_element_activity

Output:

create table {{%elementactivity}} ...Exception: SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'craft_elementactivity' already exists
The SQL being executed was: CREATE TABLE craft_elementactivity (
elementId int(11) NOT NULL,
userId int(11) NOT NULL,
siteId int(11) NOT NULL,
draftId int(11) NULL DEFAULT NULL,
type varchar(255) NOT NULL,
timestamp datetime(0),
PRIMARY KEY(elementId, userId, type)
) ENGINE = InnoDb DEFAULT CHARACTER SET = utf8 (/var/www/html/vendor/yiisoft/yii2/db/Schema.php:676)
#0 /var/www/html/vendor/yiisoft/yii2/db/Command.php(1307): yii\db\Schema-&gt;convertException(Object(PDOException), 'CREATE TABLE c...')
#1 /var/www/html/vendor/yiisoft/yii2/db/Command.php(1102): yii\db\Command-&gt;internalExecute('CREATE TABLE c...')
#2 /var/www/html/vendor/yiisoft/yii2/db/Migration.php(322): yii\db\Command-&gt;execute()
#3 /var/www/html/vendor/craftcms/cms/src/migrations/m230710_162700_element_activity.php(25): yii\db\Migration-&gt;createTable('{{%elementactiv...', Array)
#4 /var/www/html/vendor/craftcms/cms/src/db/Migration.php(49): craft\migrations\m230710_162700_element_activity-&gt;safeUp()
#5 /var/www/html/vendor/craftcms/cms/src/db/MigrationManager.php(233): craft\db\Migration-&gt;up(true)
#6 /var/www/html/vendor/craftcms/cms/src/db/MigrationManager.php(149): craft\db\MigrationManager-&gt;migrateUp(Object(craft\migrations\m230710_162700_element_activity))
#7 /var/www/html/vendor/craftcms/cms/src/services/Updates.php(245): craft\db\MigrationManager-&gt;up()
#8 /var/www/html/vendor/craftcms/cms/src/controllers/BaseUpdaterController.php(493): craft\services\Updates-&gt;runMigrations(Array)
#9 /var/www/html/vendor/craftcms/cms/src/controllers/UpdaterController.php(203): craft\controllers\BaseUpdaterController-&gt;runMigrations(Array, 'restore-db')
#10 [internal function]: craft\controllers\UpdaterController-&gt;actionMigrate()
#11 /var/www/html/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#12 /var/www/html/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction-&gt;runWithParams(Array)
#13 /var/www/html/vendor/yiisoft/yii2/base/Module.php(552): yii\base\Controller-&gt;runAction('migrate', Array)
#14 /var/www/html/vendor/craftcms/cms/src/web/Application.php(304): yii\base\Module-&gt;runAction('updater/migrate', Array)
#15 /var/www/html/vendor/craftcms/cms/src/web/Application.php(694): craft\web\Application-&gt;runAction('updater/migrate')
#16 /var/www/html/vendor/craftcms/cms/src/web/Application.php(241): craft\web\Application-&gt;_processUpdateLogic(Object(craft\web\Request))
#17 /var/www/html/vendor/yiisoft/yii2/base/Application.php(384): craft\web\Application-&gt;handleRequest(Object(craft\web\Request))
#18 /var/www/html/public/index.php(21): yii\base\Application-&gt;run()
#19 {main}
</code></pre>

<craft4>
Migration failed - table already exists
# Migration failed - table already exists

(Asked by: username_0 on 2023-12-07)

I'm stuck in a "migration" that is trying to install a table which it clearly didn't check for (because yes, it is quite already there.)
When I remove the table and allow the migration to go through, Campaign blows up.
Craft is on 4.5.4
Question: how do I get around this? Get past this?
One of Craft CMS’s migrations failed.
Database Exception: SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'craft_elementactivity' already exists
The SQL being executed was: CREATE TABLE craft_elementactivity (
elementId int(11) NOT NULL,
userId int(11) NOT NULL,
siteId int(11) NOT NULL,
draftId int(11) NULL DEFAULT NULL,
type varchar(255) NOT NULL,
timestamp datetime(0),
PRIMARY KEY(elementId, userId, type)
) ENGINE = InnoDb DEFAULT CHARACTER SET = utf8

Migration: craft\migrations\m230710_162700_element_activity

Output:

create table {{%elementactivity}} ...Exception: SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'craft_elementactivity' already exists
The SQL being executed was: CREATE TABLE craft_elementactivity (
elementId int(11) NOT NULL,
userId int(11) NOT NULL,
siteId int(11) NOT NULL,
draftId int(11) NULL DEFAULT NULL,
type varchar(255) NOT NULL,
timestamp datetime(0),
PRIMARY KEY(elementId, userId, type)
) ENGINE = InnoDb DEFAULT CHARACTER SET = utf8 (/var/www/html/vendor/yiisoft/yii2/db/Schema.php:676)
#0 /var/www/html/vendor/yiisoft/yii2/db/Command.php(1307): yii\db\Schema->convertException(Object(PDOException), 'CREATE TABLE c...')
#1 /var/www/html/vendor/yiisoft/yii2/db/Command.php(1102): yii\db\Command->internalExecute('CREATE TABLE c...')
#2 /var/www/html/vendor/yiisoft/yii2/db/Migration.php(322): yii\db\Command->execute()
#3 /var/www/html/vendor/craftcms/cms/src/migrations/m230710_162700_element_activity.php(25): yii\db\Migration->createTable('{{%elementactiv...', Array)
#4 /var/www/html/vendor/craftcms/cms/src/db/Migration.php(49): craft\migrations\m230710_162700_element_activity->safeUp()
#5 /var/www/html/vendor/craftcms/cms/src/db/MigrationManager.php(233): craft\db\Migration->up(true)
#6 /var/www/html/vendor/craftcms/cms/src/db/MigrationManager.php(149): craft\db\MigrationManager->migrateUp(Object(craft\migrations\m230710_162700_element_activity))
#7 /var/www/html/vendor/craftcms/cms/src/services/Updates.php(245): craft\db\MigrationManager->up()
#8 /var/www/html/vendor/craftcms/cms/src/controllers/BaseUpdaterController.php(493): craft\services\Updates->runMigrations(Array)
#9 /var/www/html/vendor/craftcms/cms/src/controllers/UpdaterController.php(203): craft\controllers\BaseUpdaterController->runMigrations(Array, 'restore-db')
#10 [internal function]: craft\controllers\UpdaterController->actionMigrate()
#11 /var/www/html/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#12 /var/www/html/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams(Array)
#13 /var/www/html/vendor/yiisoft/yii2/base/Module.php(552): yii\base\Controller->runAction('migrate', Array)
#14 /var/www/html/vendor/craftcms/cms/src/web/Application.php(304): yii\base\Module->runAction('updater/migrate', Array)
#15 /var/www/html/vendor/craftcms/cms/src/web/Application.php(694): craft\web\Application->runAction('updater/migrate')
#16 /var/www/html/vendor/craftcms/cms/src/web/Application.php(241): craft\web\Application->_processUpdateLogic(Object(craft\web\Request))
#17 /var/www/html/vendor/yiisoft/yii2/base/Application.php(384): craft\web\Application->handleRequest(Object(craft\web\Request))
#18 /var/www/html/public/index.php(21): yii\base\Application->run()
#19 {main}

**Tags:** craft4

---

## 1 answers

### Answer by username_1 on 2023-12-07. Score: 1 | Accepted answer

You should be able to use:
php craft migrate/mark

...to update the DB to tell it that the migration has actually already been run.
In your specific case, that would be:
php craft migrate/mark m230710_162700_element_activity

ref: https://www.yiiframework.com/doc/guide/2.0/en/db-migrations#modifying-migration-history
That's assuming this migration is one that Craft created. If it's a migration that the Campaign plugin created, do:
php craft migrate/mark --plugin=campaign m230710_162700_element_activity

...so that it knows to look for the migration from that specific plugin, rather than looking for the migration from Craft.
ref: https://craftcms.com/docs/4.x/console-commands.html#migrate-mark
"The command will modify the migration table by adding or deleting certain rows to indicate that the database has been applied migrations to the specified one. No migrations will be applied or reverted by this command."


---

