Hello,
i want to use migration in my installer/setup tool for my application.
the situation is like that:
i want to create my install script in fuel with hvmc and everything
but i think before its gonna migrate(creates the database structure) its try to connect to the settings from config/db.php
so it cant create the structure where the application is going to connect afterwards
My question is, is there a way to disable sql connection(without selecting database) attempts temporary, that i can create the db-structure?
thanks in advance!
Fuel doesn't load anything automatically (without you initiating something).
When you use any DB method, it will connect to the selected database if no connection is present. That should not be a problem as you need a connection to a database before you can do migrations.
You have to make sure the credentials are correct for the selected database (identified by db.active). So your installer has to ask for them first, read the db config, update it with the correct credentials and database name, and write it back.
After this, you should be able to connect to the database. Do this in a try/catch block, so you can catch any connection errors (which you will have to do anyway since the user could have entered the incorrect credentials).
Im now at the stage where the migration and all should work.
But im getting a sql error where i dont know what to do anymore to solve this problem.
sql error:
Fuel\Core\Database_Exception [ 1064 ]: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'NOT NULL, `creation_date` timestamp DEFAULT CURRENT_TIMESTAMP NOT NULL, PRIMAR' at line 5 [ CREATE TABLE IF NOT EXISTS `dummy_news` ( `id` int(10) NOT NULL AUTO_INCREMENT, `title` varchar(80) NOT NULL, `picture` varchar(80) NOT NULL, `text` varchar NOT NULL, `creation_date` timestamp DEFAULT CURRENT_TIMESTAMP NOT NULL, PRIMARY KEY `id` (`id`) ) DEFAULT CHARACTER SET utf8; ]
php code:
\DBUtil::create_table( 'dummy_news', array(
'id' => array('type' => 'int', 'constraint' => 10,'auto_increment' => true),
'title' => array('type' => 'varchar', 'constraint' => 80),
'picture' => array('type' => 'varchar', 'constraint' => 80),
'text' => array('type' => 'varchar'),
'creation_date' => array('type' => 'timestamp','default' => \DB::expr('CURRENT_TIMESTAMP')),
), array('id'));
thanks in advance!