Add new section in Craft 3 Migrations I have been trying to get my head wrapped around Migrations in Craft 3 and find myself struggling with added a new section.

I have managed to add a new volume, but not a section. Here’s where I have got to so far…

&lt;?php

namespace craft\contentmigrations;

use Craft;
use craft\db\Migration;

/**
 * m180428_195138_test migration.
 */
class m180428_195138_test extends Migration
{
    /**
     * @inheritdoc
     */
    public function safeUp()
    {

      if (is_null(Craft::$app-&gt;volumes-&gt;getVolumeByHandle("newvolume"))) {
        $volume = new \craft\volumes\Local([
          "name" =&gt; "New volume",
          "handle" =&gt; "newvolume",
          "hasUrls" =&gt; true,
          "url" =&gt; "@web/images/newvolume",
          "path" =&gt; "@webroot/images/newvolume"
        ]);

        Craft::$app-&gt;volumes-&gt;saveVolume($volume);
      }


      if (is_null(Craft::$app-&gt;sections-&gt;getSectionByHandle("awesomeNews"))) {
        $section = new \craft\models\Section([
          'name' =&gt; 'Awesome News',
          'handle' =&gt; 'awesomeNews',
          'type' =&gt; 'Channel',
          'siteSettings' =&gt; [
              new \craft\models\Section_SiteSettings([
                  'siteId' =&gt; Craft::$app-&gt;sites-&gt;getPrimarySite()-&gt;id,
                  'enabledByDefault' =&gt; true,
                  'hasUrls' =&gt; true,
                  'uriFormat' =&gt; 'foo/{slug}',
                  'template' =&gt; 'foo/_entry',
              ]),
          ]
        ], true);

        Craft::$app-&gt;sections-&gt;saveSection($section);

      }


    }

    /**
     * @inheritdoc
     */
    public function safeDown()
    {

      $newvolume = Craft::$app-&gt;volumes-&gt;getVolumeByHandle("newvolume");
      if (!is_null($newvolume)) {
        Craft::$app-&gt;volumes-&gt;deleteVolumeById($newvolume-&gt;id);
      }

      $awesomeNews = Craft::$app-&gt;sections-&gt;getSectionByHandle("awesomeNews");
      if (!is_null($awesomeNews)) {
        Craft::$app-&gt;volumes-&gt;deleteSectionById($awesomeNews-&gt;id);
      }

    }
}


The migration states it has been successful, however, I only see the new volume, not the section. I have tried to execute this with only the block relating to the section.

Does anyone know if it is possible to create a new section with Migrations? If it is, any idea what may be wrong with the above?
As documentation for Migrations is pretty slim, here is the working code:

&lt;?php

namespace craft\contentmigrations;

use Craft;
use craft\db\Migration;

/**
 * m180428_195138_test migration.
 */
class m180428_195138_test extends Migration
{
    /**
     * @inheritdoc
     */
    public function safeUp()
    {


      if (is_null(Craft::$app-&gt;volumes-&gt;getVolumeByHandle("newvolume"))) {
        $volume = new \craft\volumes\Local([
          "name" =&gt; "New volume",
          "handle" =&gt; "newvolume",
          "hasUrls" =&gt; true,
          "url" =&gt; "@web/images/newvolume",
          "path" =&gt; "@webroot/images/newvolume"
        ]);

        $success = Craft::$app-&gt;volumes-&gt;saveVolume($volume);

      }

      if (is_null(Craft::$app-&gt;sections-&gt;getSectionByHandle("awesomeNews"))) {
        $section = new \craft\models\Section([
          "name" =&gt; "Awesome News",
          "handle" =&gt; "awesomeNews",
          "type" =&gt; \craft\models\Section::TYPE_CHANNEL,
          "siteSettings" =&gt; [
              new \craft\models\Section_SiteSettings([
                  "siteId" =&gt; Craft::$app-&gt;sites-&gt;getPrimarySite()-&gt;id,
                  "enabledByDefault" =&gt; true,
                  "hasUrls" =&gt; true,
                  "uriFormat" =&gt; "foo/{slug}",
                  "template" =&gt; "foo/_entry",
              ]),
          ]
        ]);

        $success = Craft::$app-&gt;sections-&gt;saveSection($section);

        $errors = $section-&gt;getErrors();
        foreach ($errors as $error) {
          echo $error[0];
        }

      }

      return $success;

    }

    /**
     * @inheritdoc
     */
    public function safeDown()
    {

      $newvolume = Craft::$app-&gt;volumes-&gt;getVolumeByHandle("newvolume");
      if (!is_null($newvolume)) {
        $success = Craft::$app-&gt;volumes-&gt;deleteVolumeById($newvolume-&gt;id);
      }

      $awesomeNews = Craft::$app-&gt;sections-&gt;getSectionByHandle("awesomeNews");
      if (!is_null($awesomeNews)) {
        $success = Craft::$app-&gt;sections-&gt;deleteSectionById($awesomeNews-&gt;id);
      }

      return $success;

    }


}


This includes the error checking when creating the new section and the save functions are assigned to a variable which are returned at the end.