Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't manage to put data into my database

I am using Symfony 2.0 beta3 and I am facing a rather strange problem. I have set up the ORM with a sqlite database following the instructions of the website but when I type:

php app/console doctrine:database:create

then

php app/console doctrine:schema:create

and finally

php app/console doctrine:schema:update --force

I don't get any error (for example last command outputs "Database schema updated successfully") but nothing is actually inserted into the database. The table aren't even created. The database file is generated after the first command but remains empty.

Since I have configured FOS_UserBundle I should have for example a table fos_user… When I type

 php app/console doctrine:schema:update --dump-sql

It shows that three SQL requests are pending… If I execute these three requests using SQLiteManager, it works (so the fos_user table is created) but when I want to create a user using:

php app/console fos:user:create

I get a "SQLSTATE[HY000]: General error: 1 no such table: fos_user " error.

Why am I not given some error message when I run the first three commands? Am I missing something?

I face the same behaviour using pdo_pgsql driver, except that the SQL generated by the dump is not ANSI compliant so it can't be executed for postgresql (use of datetime and autoincrement instead of timestamp and serial)….

Any help would be much appreciated

like image 538
nimser Avatar asked Jun 05 '11 08:06

nimser


People also ask

Can data be put directly into the database?

You can add data into a database using any of the following methods: Direct entry. Form. Import.

How do I change permissions on a database?

Right-click the database server and click Permissions. Choose the user from the list. Check the Server administrator check box to grant the user server administrator privileges. Uncheck the Server administrator check box to revoke the user server administrator privileges.


1 Answers

I found this solution on the Symfony forums.

It would seem the helpers aren't creating two things that you need for the sqlite implementation to work correctly.

Firstly, in the parameters.ini for the project (tweak to suit):

 database_path=%kernel.root_dir%/config/MyDatabase.db

Secondly, in the config.yml file in the doctrine.dbal section, add the following:

 path: %database_path%

Then run:

php app/console doctrine:database:create

and it should generate the database for you in the app/config folder.

You will need to run:

php app/console doctrine:schema:create

to create the schema. Re-run the code that didn't work and it should work fine.

like image 187
lotsoffreetime Avatar answered Sep 30 '22 06:09

lotsoffreetime