I am working on a new project using Symfony and am trying to set up the database in my local environment. I am using Symfony v. 2.3.7, PropelBundle 1.2.13 with Propel 1.7, Mac OS X 10.9, and PHP 5.4.17.
I am able to create the database using propel:database:create
and delete it using propel:database:drop
. I can also use the SQL generated by propel:sql:build
and directly insert it into the database, and then delete the tables using propel:tables:drop
.
My problem is that propel:sql:insert --force
and propel:build --insert-sql
do not insert anything into the database. The console does not give an error, but instead states:
Use connection named default in dev environment.
All SQL statements have been inserted.
<?xml version="1.0" encoding="UTF-8" ?>
<database name="portfolio" namespace="KristianRandall\Bundle\PortfolioBundle\Model" defaultIdMethod="native">
<table name="category">
<column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true"/>
<column name="name" type="varchar" primaryString="true" size="100" required="true"/>
<column name="description" type="longvarchar"/>
</table>
<table name="project">
<column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true"/>
<column name="name" type="varchar" primaryString="true" size="100" required="true"/>
<column name="content" type="longvarchar"/>
<column name="date" type="date"/>
</table>
<table name="page">
<column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true"/>
<column name="name" type="varchar" primaryString="true" size="100" required="true"/>
<column name="content" type="longvarchar"/>
</table>
</database>
propel:sql:build
)# This is a fix for InnoDB in MySQL >= 4.1.x
# It "suspends judgement" for fkey relationships until are tables are set.
SET FOREIGN_KEY_CHECKS = 0;
-- ---------------------------------------------------------------------
-- category
-- ---------------------------------------------------------------------
DROP TABLE IF EXISTS `category`;
CREATE TABLE `category`
(
`id` INTEGER NOT NULL AUTO_INCREMENT,
`name` VARCHAR(100) NOT NULL,
`description` TEXT,
PRIMARY KEY (`id`)
) ENGINE=MyISAM;
-- ---------------------------------------------------------------------
-- project
-- ---------------------------------------------------------------------
DROP TABLE IF EXISTS `project`;
CREATE TABLE `project`
(
`id` INTEGER NOT NULL AUTO_INCREMENT,
`name` VARCHAR(100) NOT NULL,
`content` TEXT,
`date` DATE,
PRIMARY KEY (`id`)
) ENGINE=MyISAM;
-- ---------------------------------------------------------------------
-- page
-- ---------------------------------------------------------------------
DROP TABLE IF EXISTS `page`;
CREATE TABLE `page`
(
`id` INTEGER NOT NULL AUTO_INCREMENT,
`name` VARCHAR(100) NOT NULL,
`content` TEXT,
PRIMARY KEY (`id`)
) ENGINE=MyISAM;
# This restores the fkey checks, after having unset them earlier
SET FOREIGN_KEY_CHECKS = 1;
There is no output in my dev log, no changes in my database, and no error in the console.
I am trying to insert SQL via the propel:sql:insert --force
or propel:build --insert-sql
commands, and neither is working, but all the other commands are. I tried deleted the propel code and reinstalling (via composer) but to no avail. Has anyone encountered this problem before, and how is this resolved?
I finally analysed the code of propel and found a dirty trick to avoid that :
When you declare your connection in config.yml :
dbal:
default_connection: default
connections:
default:
driver: pdo_mysql
user: root
password: mysql
dsn: mysql:host=127.0.0.1;dbname=propeltest
Change "default" to your dbname. Here, propeltest :
dbal:
default_connection: propeltest
connections:
propeltest:
driver: pdo_mysql
user: root
password: mysql
dsn: mysql:host=127.0.0.1;dbname=propeltest
You have now two connections in the arg $connections in the setConnections($connections) function in /vendor/propel/propel1/generator/lib/util/PropelSqlManager.php line 51.
var_dump example :
array(2) {
["propeltest"]=>
array(8) {
["dsn"]=>
string(38) "mysql:host=127.0.0.1;dbname=propeltest"
["user"]=>
string(4) "root"
["password"]=>
string(5) "mysql"
["classname"]=>
string(8) "DebugPDO"
["options"]=>
array(0) {
}
["attributes"]=>
array(0) {
}
["settings"]=>
array(0) {
}
["model_paths"]=>
array(2) {
[0]=>
string(4) "src/"
[1]=>
string(7) "vendor/"
}
}
["default"]=>
array(8) {
["dsn"]=>
string(38) "mysql:host=127.0.0.1;dbname=propeltest"
["user"]=>
string(4) "root"
["password"]=>
string(5) "mysql"
["classname"]=>
string(8) "DebugPDO"
["options"]=>
array(0) {
}
["attributes"]=>
array(0) {
}
["settings"]=>
array(0) {
}
["model_paths"]=>
array(2) {
[0]=>
string(4) "src/"
[1]=>
string(7) "vendor/"
}
}
}
I don't understand why propel creates a "default connection" but this trick works without changing the source code of propel.