最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - he Symfony application is unable to connect to the database. `doctrine:fixtures:load` - Stack Overflow

programmeradmin5浏览0评论

I’m trying to load fixtures in my Symfony project using the command:

symfony console doctrine:fixtures:load

However, I’m encountering the following error:

 Careful, database "gestionexams" will be purged. Do you want to continue? (yes/no) [no]:
 > yes

   > purging database
   > loading App\DataFixtures\AppFixtures

In ExceptionConverter.php line 115:

  An exception occurred while executing a query: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'semestre_id' cannot be null  


In Exception.php line 24:

  SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'semestre_id' cannot be null  


In Statement.php line 130:

  SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'semestre_id' cannot be null  


doctrine:fixtures:load [--append] [--group GROUP] [--em EM] [--purger PURGER] [--purge-exclusions PURGE-EXCLUSIONS] [--purge-with-truncate]

What I’ve Tried:

  • Checked Database Server Status: Confirmed that MySQL/PostgreSQL is running.
  • Verified .env Configuration: My .env file contains:
DATABASE_URL="mysql://root:@127.0.0.1:3306/GestionExams?serverVersion=10.4.21-MariaDB&charset=utf8mb4"
  • Tested Database Connection: I can connect to the database using a database client MySQL
  • Cleared Symfony Cache: i run php bin/console cache:clear to ensure the cache isn’t causing the issue.

Additional Information:

  • Symfony Version: 6.3.

  • Database: MySQL.

  • Environment: Local development .

  • Relevant Code: My DATABASE_URL in .env is:

DATABASE_URL="mysql://root:@127.0.0.1:3306/GestionExams?serverVersion=10.4.21-MariaDB&charset=utf8mb4"
  • this my (repo)[] repo

I’m trying to load fixtures in my Symfony project using the command:

symfony console doctrine:fixtures:load

However, I’m encountering the following error:

 Careful, database "gestionexams" will be purged. Do you want to continue? (yes/no) [no]:
 > yes

   > purging database
   > loading App\DataFixtures\AppFixtures

In ExceptionConverter.php line 115:

  An exception occurred while executing a query: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'semestre_id' cannot be null  


In Exception.php line 24:

  SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'semestre_id' cannot be null  


In Statement.php line 130:

  SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'semestre_id' cannot be null  


doctrine:fixtures:load [--append] [--group GROUP] [--em EM] [--purger PURGER] [--purge-exclusions PURGE-EXCLUSIONS] [--purge-with-truncate]

What I’ve Tried:

  • Checked Database Server Status: Confirmed that MySQL/PostgreSQL is running.
  • Verified .env Configuration: My .env file contains:
DATABASE_URL="mysql://root:@127.0.0.1:3306/GestionExams?serverVersion=10.4.21-MariaDB&charset=utf8mb4"
  • Tested Database Connection: I can connect to the database using a database client MySQL
  • Cleared Symfony Cache: i run php bin/console cache:clear to ensure the cache isn’t causing the issue.

Additional Information:

  • Symfony Version: 6.3.

  • Database: MySQL.

  • Environment: Local development .

  • Relevant Code: My DATABASE_URL in .env is:

DATABASE_URL="mysql://root:@127.0.0.1:3306/GestionExams?serverVersion=10.4.21-MariaDB&charset=utf8mb4"
  • this my (repo)[https://github/marouane-sadoune/GEXAMS] repo
Share edited Mar 9 at 0:18 Marouane Sadoune asked Mar 8 at 23:52 Marouane SadouneMarouane Sadoune 154 bronze badges 1
  • 1 The error is pretty explicit. You are setting a field to null that cannot be null, per your own database definition. We cannot see the db definition or even the db fixtures, but the solution seems clear enough: either accept null for "semester", or set a value to "semester_id". – yivi Commented Mar 9 at 10:50
Add a comment  | 

1 Answer 1

Reset to default 1

You need to make the field nullable in the entity file, then update de database, then try again

发布评论

评论列表(0)

  1. 暂无评论