CakeDC / migrations

Migrations Plugin for CakePHP

Home Page:http://cakedc.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can not create table schema_migrations when Init plugin

buidan opened this issue · comments

Cakephp: 2.7.3
Mysql: 5.5.42

I got this problem when ran the app buidan$ Console/cake Migrations.migration run all -p Migrations at beginning.
app buidan$ Console/cake Migrations.migration run all -p Migrations ... Error: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'database_name.schema_migrations' doesn't exist #0 /projects/lib/Cake/Model/Datasource/DboSource.php(461): PDOStatement->execute(Array) #1 /projects/lib/Cake/Model/Datasource/DboSource.php(427): DboSource->_execute('SELECTSchemaM...', Array)
#2 /projects/lib/Cake/Model/Datasource/DboSource.php(669): DboSource->execute('SELECT SchemaM...', Array, Array) #3 /projects/lib/Cake/Model/Datasource/DboSource.php(1114): DboSource->fetchAll('SELECT SchemaM...', Array)
#4 /projects/lib/Cake/Model/Model.php(3026): DboSource->read(Object(SchemaMigration), Array)
#5 /projects/lib/Cake/Model/Model.php(2998): Model->_readDataSource('all', Array)
#6 /projects/app/Plugin/Migrations/Lib/MigrationVersion.php(233): Model->find('all', Array)
#7 /projects/app/Plugin/Migrations/Lib/MigrationVersion.php(448): MigrationVersion->getMapping('Migrations')
#8 /projects/app/Plugin/Migrations/Lib/MigrationVersion.php(128): MigrationVersion->_initMigrations()
#9 /projects/app/Plugin/Migrations/Console/Command/MigrationShell.php(118): MigrationVersion->__construct(Array)
#10 /projects/lib/Cake/Console/Shell.php(436): MigrationShell->startup()
#11 /projects/lib/Cake/Console/ShellDispatcher.php(212): Shell->runCommand('run', Array)
#12 /projects/lib/Cake/Console/ShellDispatcher.php(66): ShellDispatcher->dispatch()
#13 /projects/app/Console/cake.php(47): ShellDispatcher::run(Array)
#14 {main}
`
Please help me to explain why it happened.
Thank you!

Hi @buidan, it seems you don't have the database created, do you have?

Hi @pmoraes . Of course i have the database called 'database_name' , but at the beginning i don't have schema_migrations table in the database.
As normal the 001_init_migrations.php in this plugin will take care about the create 'schema_migrations' table stuff.
But not i have to create table schema_migrations manually and delete all init migrations from this plugin.
(if i create manually and not remove init migrations. it will throw another error says that the schema_migrations's already exist)

I am also experiencing this problem. If I manually create the table, I get an error that the table already exists. If I delete the table, I get an error that the table does not exist.

Ah. I see the issue. $db->listSources() in Lib/MigrationVersion.php (line 439) shows that schema_migrations exists. Once I cleared my local cache I was able to init the table properly.

@buidan I was trying to replicate this issue here, but I can't, please clear your cache in tmp/cache and check again. If you see this issue again, please let us know.
Thanks.