Answers.Body: <p>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 <a href="https://docs.craftcms.com/v3/plugin-migrations.html#install-migrations" rel="nofollow noreferrer">Install migration</a>.</p>
  
  <p>That will run every time someone does a fresh installation of your plugin.</p>
  
  <p>For the people that already have your plugin installed, you need to <a href="https://docs.craftcms.com/v3/plugin-migrations.html#creating-migrations" rel="nofollow noreferrer">create a migration</a> that also creates the table.  The code for the table creation will be very similar in both places.</p>
  
  <p>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 <a href="https://docs.craftcms.com/v3/plugin-migrations.html#executing-migrations" rel="nofollow noreferrer">schema version number</a>.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-08T21:47:08.110Z
Answers.LastActivityDate: 2018-05-08T21:47:08.110Z
Answers.UserDisplayName: Brad Bell
Body: <p>I followed the document to create a migration, add a schema version, install migration and add schema codes into <code>Install.php</code>. Last I run the migrate up command, but no table is created. Anyone could tell me what is going wrong please?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-05-08T00:25:47.783Z
Comments.Text: You install.php is only executed during the installation of your plugin. Do you want to create a migration on installation or just as an update?
Comments.UserDisplayName: Robin Schambach
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-05-08T00:29:35.107Z
Comments.Text: @RobinSchambach I want to create a new table. If I reinstall the plugin, I'm not sure if any data will be lost
Comments.UserDisplayName: yu xia
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-05-08T00:30:56.750Z
Comments.Text: Usually not. Craft 3 won't delete any data on it's own. If it is your plugin and you didn't include custom logic to delete certain things you can delete the plugin without any issues and install it again. However.. You can just do `(new Install())->safeUp();` as well
Comments.UserDisplayName: Robin Schambach
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-05-08T01:37:10.920Z
Comments.Text: @RobinSchambach what if I just run ```./craft migrate/create <migration_name> --plugin=<plugin-handle>``` to create a migration, and copy the schema code into its ```safeUp()``` function
  
  And run ```./craft migrate/up --plugin=<plugin-handle>```
  The table will be created in this way without re-install the plugin?
Comments.UserDisplayName: yu xia
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-05-08T09:05:27.200Z
Comments.Text: is there a certain reason why you want to use the CLI? I never did that because the `(new Install())->safeUp()` method is way faster and easier. I never tried it your way
Comments.UserDisplayName: Robin Schambach
Tags: <plugin-development><database><table>
Title: how to create a new table in database
ThreadText: # how to create a new table in database
  
  (Asked by: username_0 on 2018-05-08)
  
  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?
  
  **Tags:** plugin-development, database, table
  
  > **Comments:**
  > **username_1**: You install.php is only executed during the installation of your plugin. Do you want to create a migration on installation or just as an update?  
  > **username_0**: @username_1 I want to create a new table. If I reinstall the plugin, I'm not sure if any data will be lost  
  > **username_1**: Usually not. Craft 3 won't delete any data on it's own. If it is your plugin and you didn't include custom logic to delete certain things you can delete the plugin without any issues and install it again. However.. You can just do `(new Install())->safeUp();` as well  
  > **username_0**: @username_1 what if I just run ```./craft migrate/create <migration_name> --plugin=<plugin-handle>``` to create a migration, and copy the schema code into its ```safeUp()``` function  And run ```./craft migrate/up --plugin=<plugin-handle>``` The table will be created in this way without re-install the plugin?  
  > **username_1**: is there a certain reason why you want to use the CLI? I never did that because the `(new Install())->safeUp()` method is way faster and easier. I never tried it your way  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2018-05-08. Score: 2
  
  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](https://docs.craftcms.com/v3/plugin-migrations.html#install-migrations).
  
  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](https://docs.craftcms.com/v3/plugin-migrations.html#creating-migrations) 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](https://docs.craftcms.com/v3/plugin-migrations.html#executing-migrations).
  
  
  ---
  
  