Creating and saving a GlobalSet element type in Craft 3 The following code is in a migration. It runs fine and there are no errors and prints SAVED, but nothing is saved in the globalsets database table. 

All my other content migrations run fine so it is not a DB issue. 

    $globalConfig = [
      "type" =&gt; \craft\elements\GlobalSet::class,
      "settings" =&gt; [
        "name" =&gt; "Meta",
        "handle" =&gt; "meta"
      ],
    ];

    $element = Craft::$app-&gt;getElements()-&gt;createElement($globalConfig);

    if (Craft::$app-&gt;getElements()-&gt;saveElement($element)) {
        print "SAVED";
    }


Why is this not saving ?
Answer: 

So I looked in the craft core to see how the CP does it. Turns out we have to use this 

$gs = new \craft\elements\GlobalSet();
$gs-&gt;name = "Meta";
$gs-&gt;handle = "meta";

Craft::$app-&gt;getGlobals()-&gt;saveSet($gs);


Hope this helps someone. 

Craft core reference

https://github.com/craftcms/cms/blob/develop/src/controllers/GlobalsController.php#L55-L96