This repository has been archived on 2024-08-26. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/docs/Database.md

37 lines
832 B
Markdown
Raw Normal View History

# Working with symfony database
## Setting up a Database table
### Part 1 - Entity Class
```bash
php bin/console make:entity
```
And then follow the instructions.
This will create a entity class in src/Entity
**Note: ** You can run make:entity again with the same Entity name to add more fields.
You will have to run make:migration and then doctrine:migrations:migrate
The system is smart enough not to duplicate work.
## Part 2 - Create Migration
To create a migration from the entity, run:
```bash
2022-12-18 09:37:39 +00:00
sudo docker-compose run php bin/console make:migration
```
A file will be created in the migrations folder.
## Part 3 - Create the table (run migration)
```bash
2022-12-18 09:37:39 +00:00
sudo docker-compose run php php bin/console doctrine:migrations:migrate
```
## References
* [Symfony doctrine](https://symfony.com/doc/current/doctrine.html)