October: create new plugin can't create table

Created on 28 Jun 2019  路  3Comments  路  Source: octobercms/october

When I create a new plugin php artisan create:plugin Winson.Test, after that I create a model with php artisan create:model Winson.Test posts, and run php artisan plugin:refresh Winson.Test, mysql can't see the table winson_test_posts.
How can I create the table?

Question

Most helpful comment

First, it is better to create models in the singular, in your case Post
Secondly, in order for the migrations to work, you need to add them to updates/version.yml:

1.0.1:
聽聽 - Run table migrations
聽聽 - create_posts_table.php

procedure:

  1. php artisan create: plugin Winson.Test
  2. php artisan create: model Winson.Test Post
  3. add your table to the migration file
  4. Raise the version of the plugin php artisan october:up or update it php artisan plugin:refresh Winson.Test

All 3 comments

First, it is better to create models in the singular, in your case Post
Secondly, in order for the migrations to work, you need to add them to updates/version.yml:

1.0.1:
聽聽 - Run table migrations
聽聽 - create_posts_table.php

procedure:

  1. php artisan create: plugin Winson.Test
  2. php artisan create: model Winson.Test Post
  3. add your table to the migration file
  4. Raise the version of the plugin php artisan october:up or update it php artisan plugin:refresh Winson.Test

@yinglau creating the model doesn't automatically add its migration file to the version.yaml file (required for the migration to be run). See https://octobercms.com/docs/plugin/updates#migration-seed-files

As a side note, models should always be named with a singular name (i.e. Post) and tables and controllers with the plural form of that name.

First, it is better to create models in the singular, in your case Post
Secondly, in order for the migrations to work, you need to add them to updates/version.yml:

1.0.1:
聽聽 - Run table migrations
聽聽 - create_posts_table.php

procedure:

  1. php artisan create: plugin Winson.Test
  2. php artisan create: model Winson.Test Post
  3. add your table to the migration file
  4. Raise the version of the plugin php artisan october:up or update it php artisan plugin:refresh Winson.Test

@jexme
Thanks guy, cool.

Was this page helpful?
0 / 5 - 0 ratings