Symfony framework database migration - php

I am laravel dev and now working with Symfony for few days. I have clone a git form bitbucket and wanted to migrate the database. But on laravel we can easily migrate all tables to database I cant find option on Symfony. How can I migrate my tables to mysql? Do I need menually import tables to mysql?

No.
1.Find app/config/parameters.yml:
parameters:
database_host: localhost
database_name: databaseName
database_user: root
database_password: password
2.Create database, with console:
In Symfony 2: php app/console doctrine:database:create
In Symfony 3: php bin/console doctrine:database:create
3.Migrate Tables
In Symfony 2: php app/console doctrine:migrations:migrate
In Symfony 3: php bin/console doctrine:migrations:migrate

Symfony has the bin/console command (in older versions it may be at app/console). If there already is the database and tables, but there are migrations that have not been run, you can run all the available migrations with
bin/console doctrine:migrations:migrate
You can see all the other commands with
bin/console list
or just Symfony commands that deal with database & table creation, migration and more.
bin/console list doctrine

Related

I have a problem when I try to do migration

Hello I have a project in symfony and I need to do migrations to create tables correctly to the database.
php bin/console doctrine:migrations:migrate
When I run this command to migrate I get en error as
An exception occurred in the driver: could not find driver
how can I fix it?

How to generate entities and cruds in SF4?

I've just installed symfony 4 and after noticing the structure being slightly different, searching for some config files and editing around a bit, I was planning to go and generate my first entities and cruds.
However, I found that symfony 4 does no longer support the doctrine:generate:entity command.
Instead I found that symfony now offers the MakerBundle that comes with a range of simple commands to generate the most basic code snippets.
What I am wondering is if there is still a way to interactively generate an entity and/or crud.
I tried installing the SensioGeneratorBundle but that doesn't yet seem compatible with symfony 4.
Use MakerBundle:
composer req doctrine maker
For example, create your entity:
php bin/console make:entity Product
If you want use annotations, run:
composer req annotations
...then you need this informations:
Examples the commands for to works with entities (database)
Symfony use Doctrine.
If your don't have database, run this command:
php bin/console doctrine:database:create
If you want create entities in your database:
php bin/console doctrine:schema:create
If your need update your entities, run this command:
php bin/console doctrine:schema:update --force
For help, run command:
php bin/console list doctrine
So, your can generate entities if you already have database, see list doctrine.
Create a plain old PHP object, add some doctrine annotations to it for the properties which are columns, then do a doctrine:migrations:diff. A migration file will be created with the SQL required. Then you run doctrine:migrations:migrate and the SQL will be executed.
What I am wondering is if there is still a way to interactively generate an entity and/or crud.
Why not use maker, which you mentioned?
composer require maker --dev
Then, run:
bin/console make:entity

Failed to open page after cloning Symfony PHP project

I just cloned a Symfony PHP project from Github but whenever I open a page containing the following code:
public function indexAction()
{
$em = $this->getDoctrine()->getManager();
$modules = $em->getRepository('AppBundle:Module')->findAll();
return $this->render('module/index.html.twig', array(
'modules' => $modules,
));
}
The page will return the following error:
ConnectionException: An exception occured in driver: SQLSTATE[HY000] [1049] Unknown database ''.
I am not really experienced with PHP Symfony projects yet and someone asked me to clone this and try to solve the error I will be returned with. Where do I need to look in order to fix the error? I suppose some sort of configuration file which points to database configuration?
This error mean you didn't got access to the database.
Run php app/console doctrine:database:create and after, php app/console doctrine:schema:update --force.
It will create the database on your own local server. (make sure to provide correct connection details on your app/parameter.yml file)
EDIT: Also, don't forget to update your project using composer install and composer update.
Since this is a github project, all dependencies are not pulled
You need to create database:
For Symfony2:
php app/console doctrine:database:create
For Symfony3:
php bin/console doctrine:database:create
You can see sql dump:
For Symfony2:
php app/console doctrine:schema:update --dump-sql
For Symfony3:
php bin/console doctrine:schema:update --dump-sql
Than create tables:
For Symfony2:
php app/console doctrine:schema:create
For Symfony3:
php bin/console doctrine:schema:create

Doctrine not importing particular tables

I am working on symfony2 and trying to create entities from database .My problem is that I have 12 tables in database but only 10 entities are getting generated .
Those two tables are not getting imported even when I am trying to import them individually.
I have tried commands mentioned in thread
But when I run command
php app/console doctrine:mapping:import AppMyBundle \
metadata_format --filter="Yourtablename"
it says
Database does not have any mapping information.
Sorry I am new to symfony and doctrine .Please suggest me what should I do?
At first, try to convert annotation with --from-database argument, as described in this answer:
Step1
php app/console doctrine:mapping:convert annotation /src/App/MyBundle/Resources/config/doctrine --from-database --filter="table_name"
Step2 Now you can apply importing
php app/console doctrine:mapping:import AppMyBundle annotation --filter="table_name"
Step3
php app/console doctrine:generate:entities AppMyBundle --no-backup

Symfony + Doctrine functional database testing

I found only a few lines about database functional testing in the documentation: http://symfony.com/doc/current/cookbook/testing/database.html
The problem is:
I need to install database schema from dev database to test database before testing.
I need to reinstall fixtures before each test.
It's not described in the documentation. How can I do it using symfony?
I use this command to do same job :
In console line :
doctrine:database:create --env=test
doctrine:schema:create --env=test
doctrine:fixture:load --env=test

Categories