https://github.com/symfony/demo にそってアプリを動かします。
$ symfony new --demo symfony6-playground
を実行しますCREATE DATABASE symfony6_playground DEFAULT CHARACTER SET utf8mb4;
)しますphp bin/console doctrine:fixtures:load
)symfony server:start -vvv
)- DATABASE_URL=sqlite:///%kernel.project_dir%/data/database.sqlite
+ DATABASE_URL="mysql://user:password@127.0.0.1:3306/symfony6_playground?serverVersion=mariadb-10.4.10",
MySQLに以下ユーザーおよびDBを作成済みとします。
user
password
symfony6_playground
https://symfony.com/doc/current/doctrine.html#migrations-creating-the-database-tables-schema 上記のドキュメントどおりに実行します。
以下コマンドでマイグレーションファイルが作成された(中身は必要なテーブル作成用SQL)。
$php bin/console make:migration
Success!
Next: Review the new migration "migrations/Version20220806055442.php"
Then: Run the migration with php bin/console doctrine:migrations:migrate
See https://symfony.com/doc/current/bundles/DoctrineMigrationsBundle/index.html
$ php bin/console doctrine:migrations:migrate
WARNING! You are about to execute a migration in database "symfony6_playground" that could result in schema changes and data loss. Are you sure you wish to continue? (yes/no) [yes]:
> yes
[notice] Migrating up to DoctrineMigrations\Version20220806055442
[notice] finished in 683.5ms, used 20M memory, 1 migrations executed, 10 sql queries
テーブルが作成されていることを確認します。
MariaDB [symfony6_playground]> show tables;
+-------------------------------+
| Tables_in_symfony6_playground |
+-------------------------------+
| doctrine_migration_versions |
| symfony_demo_comment |
| symfony_demo_post |
| symfony_demo_post_tag |
| symfony_demo_tag |
| symfony_demo_user |
+-------------------------------+
6 rows in set (0.001 sec)
とりあえずフィクスチャを使用する。
$ php bin/console doctrine:fixtures:load