Give us a call 888-856-2664
Get a Quote Today

Things a Chameleon Would Say

Web design

Symfony + Doctrine: How to rebuild your DB
By: Colin Foley 10/07/2010

This post is about rebuilding your database from a schema.yml file in your Symfony project (Symfony version 1.4.8 embedded in the project at /path/to/your/project/lib/vendor/symfony/lib).

If you make a change in your config/doctrine/schema.yml, run these commands from your project’s root directory.

./symfony doctrine:drop-db
./symfony doctrine:build-model
./symfony doctrine:build-sql
./symfony doctrine:create-db
./symfony doctrine:insert-sql

drop-db drops the database.
build-model creates the model from the schema file.
build-sql creates the SQL from the model.
create-db creates the database configured in config/databases.yml with the name of your project.
insert-sql inserts the SQL into the fresh database.

Note: You must drop your database in order to insert the generated SQL. The generated SQL does not include DROP TABLE or CREATE TABLE IF NOT EXISTS.
Note: These steps are for a development environment. If you run these commands you’ll lose all your data. If you have data you need saved. Make sure you run:

./symfony doctrine:data-dump

before dropping your database. This will store your data into a YAML file like data/fixtures/data.yml. After you’ve done the above steps, you can:

./symfony doctrine:data-load

in order to reinsert the data into the database.

3 Responses to “Symfony + Doctrine: How to rebuild your DB”

  1. Mohamed October 11, 2010

    Thank you
    What about if i have 9 million record in database table ?
    so “./symfony doctrine:data-dump” will not help.

    What we can do ?

  2. Colin Foley October 11, 2010

    Mohamed,
    What happens when you run doctrine:data-dump? Does the terminal freeze up? Do you get any errors? Is the file created, but blank?

    If you’re using MySQL, my first way around this would be to do a SQL dump from the database using a tool like phpMyAdmin. If you don’t have phpMyAdmin try this from the command line:

    mysqldump -u username -ppassword database_name > dump.sql

    Then to reimport your data you can try

    mysql -u username -ppassword
    mysql> use database_name;
    mysql> source dump.sql;

    Remember to be careful with this, though. If you’ve made a lot of changes to the structure of your database, inserting values into nonexistent columns may cause some serious issues.

  3. Michelangelo February 23, 2012

    Hi Colin,

    thanks for the info. I have noticed that doctrine doesn’t dump all the data of the database correctly. Many indexes are wrong, do you had any experience about it?

    thanks,
    Michelangelo

Leave a Reply




Have a Question? Need a Quote?

Drop us a line or give us a call at 888-856-2664

Your Name (required)
Your Email (required)
Phone (required)
Your Message

What Our Clients Are Saying

John,
Can I just tell you how impressed I am with your team?! This whole process has been so great and working with you guys has made it SOOOO much easier! Thank you for all your hard work and for convincing us to choose Accella.

SO THRILLED!!

Alycia White
Kubota

Recent Posts

Getting Arrested Can Help Your Business

While generally coming face to face with the law is generally not good for...

Drupal 6 with UberCart / UberPOS - A Love-Hate Relationship?

As most techies and programmers have heard, the Drupal CMS is an extremely...