I am trying to get migrations to work, but I seem to get an odd error (see title).
What I wonder is where it get’s the idea to use Cake\ORM\Table
as a table name?
These are the migrations I’m running (first one works just fine, the second one gives the error):
<?php
use Migrations\AbstractMigration;
class CreateInitialDatabase extends AbstractMigration {
/**
* Change Method.
*
* More information on this method is available here:
* http://docs.phinx.org/en/latest/migrations.html#the-change-method
* @return void
*/
public function change() {
// Create the users table
$table = $this->table('users')
->addColumn('username','string',['default' => null,'limit' => 255,'null' => false])
->addColumn('email','string',['default' => null,'null' => false])
->addColumn('password','string',['default' => null,'null' => false])
->addColumn('created','datetime',['default' => null,'null' => false])
->save();
// Create the users_details table
$table = $this->table('users_details')
->addColumn('firstname','string',['default' => null,'limit' => 255,'null' => false])
->addColumn('lastname','string',['default' => null,'limit' => 255,'null' => false])
->addForeignKey('id','users','id', ['delete'=> 'CASCADE', 'update'=> 'NO_ACTION'])
->save();
// Create the roles table
$table = $this->table('roles')
->addColumn('name','string',['default' => null,'null' => false])
->save();
// Create the user_roles table
$table = $this->table('users_roles',['id' => false,'primary_key' => ['user_id','role_id']])
->addColumn('user_id','integer',['default' => null,'limit' => 11,'null' => false])
->addColumn('role_id','integer',['default' => null,'limit' => 11,'null' => false])
->addForeignKey('user_id','users','id', ['delete'=> 'CASCADE', 'update'=> 'NO_ACTION'])
->addForeignKey('role_id','roles','id', ['delete'=> 'CASCADE', 'update'=> 'NO_ACTION'])
->save();
// Create the permissions table
$table = $this->table('permissions',['id' => false,'primary_key' => ['role_id']])
->addColumn('role_id','integer',['default' => null,'limit' => 11,'null' => false])
->addColumn('access_cms','boolean',['default' => false,'null' => false])
->addColumn('edit_settings','boolean',['default' => false,'null' => false])
->addForeignKey('role_id','roles','id', ['delete'=> 'CASCADE', 'update'=> 'NO_ACTION'])
->save();
// Create the options table
$table = $this->table('options')
->addColumn('name','string',['default' => null,'limit' => 255,'null' => false])
->addColumn('value','text',['null' => true])
->save();
}
}
<?php
use Migrations\AbstractMigration;
use Cake\ORM\TableRegistry;
class AddInitialRoles extends AbstractMigration {
/**
* Change Method.
*
* More information on this method is available here:
* http://docs.phinx.org/en/latest/migrations.html#the-change-method
* @return void
*/
public function change() {
// Load the RolesTable from the registry
$rolesTable = TableRegistry::get('Roles');
// Add an Administrator role
$role = $rolesTable->newEntity();
$role->name = 'Administrator';
$rolesTable->save($role);
// Add permissions for the Administrator role
$permissions = $rolesTable->Permissions->newEntity();
$permissions->role_id = $role->id;
$permissions->access_cms = 1;
$permissions->edit_settings = 1;
$rolesTable->Permissions->save($permissions);
// Add a Member role
$role = $rolesTable->newEntity();
$role->name = 'Member';
$rolesTable->save($role);
// Add permissions for the Member role
$permissions = $rolesTable->Permissions->newEntity();
$permissions->role_id = $role->id;
$permissions->access_cms = 0;
$permissions->edit_settings = 0;
$rolesTable->Permissions->save($permissions);
}
}
I am trying to run it using bin/cake migrations migrate -p Kikioboeru/Kikioboeru
.
The migrations did work earlier, but I re-installed my PC so had to run the migrations again, and poof.