phinx icon indicating copy to clipboard operation
phinx copied to clipboard

As a developer I want to have an example for createTable

Open Mondane opened this issue 9 years ago • 7 comments

The documentation specifies that createTable can be used in the change method, but there is no example. Only http://docs.phinx.org/en/latest/migrations.html#creating-a-table can be found. Could an example be added?

Mondane avatar May 01 '17 14:05 Mondane

Hi @Mondane have a look here for a basic exmaple: http://docs.phinx.org/en/latest/migrations.html#the-change-method. I agree the docs could be improved a bit though.

robmorgan avatar May 11 '17 08:05 robmorgan

Agree with @Mondane, I can't find how to create an unsigned primary key

jcornide avatar Oct 24 '18 08:10 jcornide

See the documentation at https://book.cakephp.org/3.0/en/phinx/migrations.html#creating-a-table, namely a bit into it it talks about setting id versus primary_key and that MySQL supports setting the signed option on the table object.

So, you could either do:

$table = $this->table('example_table', ['signed' => false]);
$table->create();

or

$table = $this->table('example_table', ['id' => false, 'primary_key' => 'pid']);
$table->addColumn('pid', 'integer')
      ->create();

MasterOdin avatar Oct 24 '18 14:10 MasterOdin

I think that what @Mondane means is that in docs and also on migration create appears this

 * The following commands can be used in this method and Phinx will
 * automatically reverse them when rolling back:
 *
 *    createTable
 *    [...]

And is a bit confusing that is not any reference elsewhere about how to use it. If is on ->create(), i think this createTable should be changed by only create, because otherwise seems like wrong.

vichaunter avatar Nov 23 '18 06:11 vichaunter

That's exactly what I mean. I'm missing examples for those commands :

  • createTable
  • renameTable
  • addColumn
  • renameColumn
  • addIndex
  • addForeignKey

For instance, for createTable, should I use the function 'createTable' or something else. I know the function exists: https://github.com/cakephp/phinx/search?q=createTable&unscoped_q=createTable .

Mondane avatar Jan 09 '19 15:01 Mondane

Confused me too. There is no "createTable" method.

matthewfedak avatar Aug 09 '19 12:08 matthewfedak

docs PR welcome

dereuromark avatar Apr 11 '20 06:04 dereuromark