I followed the document to create a migration, add a schema version, install migration and add schema codes into Install.php
. Last I run the migrate up command, but no table is created. Anyone could tell me what is going wrong please?
1 Answer
Not sure I'm following 100%, but in Craft 3, you can add the code necessary to create the new table in your plugin's Install migration.
That will run every time someone does a fresh installation of your plugin.
For the people that already have your plugin installed, you need to create a migration that also creates the table. The code for the table creation will be very similar in both places.
For the latter, in order for Craft to know a plugin has a new migration is wants to run, you'll need to bump your plugin's schema version number.
(new Install())->safeUp();
as well./craft migrate/create <migration_name> --plugin=<plugin-handle>
to create a migration, and copy the schema code into itssafeUp()
function And run./craft migrate/up --plugin=<plugin-handle>
The table will be created in this way without re-install the plugin?(new Install())->safeUp()
method is way faster and easier. I never tried it your way