<p>Actually, everything was working fine with the migration.  The issue was that I had code inside of a Twig extension and inside of a rendering hook that was being executed before the migration tried to take place.</p>

<p>I wrapped it in <code>if (!craft()-&gt;request-&gt;isCpRequest())</code> to only do its thing when it's a non-CP request (which is how it probably should have been anyway), and all is well.</p>

CC BY-SA 3.0
2015-12-27T02:33:34.460Z
2015-12-27T02:33:34.460Z
andrew.welch
<p>When exactly are migrations run?  I wrote a migration that runs and does its job properly if I run it via the command line: <code>yiic migrate up Seomatic</code> but despite the version number and schema number being bumped, Craft doesn’t run the migration automatically`</p>

<p>Instead, my code dies because of a column that doesn’t exist in the db.  Shouldn't the migration be found and run before my plugin's code is?</p>

<p>Here's the version numbers returned by my plugin:</p>

<pre><code>public function getVersion()
{
    return '1.0.5';
}

public function getSchemaVersion()
{
    return '1.0.1';
}
</code></pre>

<p>The previous installed version was '1.0.4' and '1.0.0', respectively.  Shouldn't this be enough for Craft to find and run the migration?</p>

<p>The migration is named:</p>

<pre><code>m151225_000000_seomatic_addHumansField.php
</code></pre>

<p>...with a class of the same name, and again, it's found and runs properly if manually run it via <code>yiic</code> -- what am I missing?</p>

<plugin-development><migration>
Plugin migration quandary
# Plugin migration quandary

(Asked by: username_0 on 2015-12-27)

When exactly are migrations run?  I wrote a migration that runs and does its job properly if I run it via the command line: yiic migrate up Seomatic but despite the version number and schema number being bumped, Craft doesn’t run the migration automatically`
Instead, my code dies because of a column that doesn’t exist in the db.  Shouldn't the migration be found and run before my plugin's code is?
Here's the version numbers returned by my plugin:
public function getVersion()
{
    return '1.0.5';
}

public function getSchemaVersion()
{
    return '1.0.1';
}

The previous installed version was '1.0.4' and '1.0.0', respectively.  Shouldn't this be enough for Craft to find and run the migration?
The migration is named:
m151225_000000_seomatic_addHumansField.php

...with a class of the same name, and again, it's found and runs properly if manually run it via yiic -- what am I missing?

**Tags:** plugin-development, migration


---

## 1 answers

### Answer by username_0 on 2015-12-27. Score: 4

Actually, everything was working fine with the migration. The issue was that I had code inside of a Twig extension and inside of a rendering hook that was being executed before the migration tried to take place.

I wrapped it in `if (!craft()->request->isCpRequest())` to only do its thing when it's a non-CP request (which is how it probably should have been anyway), and all is well.


---

