Symfony 1 - Error - SQL and Doctrine with the command line

In this page, I'm gathering all errors that I will find while playing with Symfony and SQL requests.
And of course I will bring some explanations to resolve these errors.
It will be sliced by an example of each error and with its own solution.
So, let's start it because a problem has always a solution!

Example 1

For example you typed this in your command line:

$ php symfony doctrine:build --all --no-confirmation ; php symfony doctrine:data-load

And you have this error:

$ Unknown record property / related component "hellolevel" on "HelloBook"

Solution 1

It is because you try to load data and you encounter an error.
Indeed in your schema.yml you did not specified a relation between your table and another one.
This other table is missing in the schema.yml or you do not have to specify it in your fixture.
For example in your books.yml file, there is certainly something like that:

# data/fixtures/books.yml
HelloBook:
  book_1:
    HelloLevel: first

Remove the HelloLevel: first line or add a relation in the schema.yml file and it would be OK!

Example 2

You typed:

$ php symfony doctrine:build --all --no-confirmation ; php symfony doctrine:data-load

And you have this error:

$ Invalid row key specified: (hello_title) titlr_1, referred to in (hello_book) book_1

Solution 2

In your books.yml file, you do not have written the correct label that is into the titles.yml file, or maybe this label does not exist.
In this case, the label titlr_1 should have been written certainly like this title_1.

Example 3

You typed:

$ php symfony doctrine:build --all --no-confirmation ; php symfony doctrine:data-load

And you have this error:

$ SQLSTATE[HY000]: General error: 1364 Field 'id_user' doesn't have a default value

Solution 3

In your schema.yml you specified, for example, the HelloBook table with a column id_user.
You also specified a relation between this table and the HelloUser one at the end of your HelloBook table in the schema.yml:

# config/doctrine/schema.yml
HelloBook:
  actAs: { Timestampable: ~ }
  columns:
    id_user: { type: integer, notnull: true }
    id_test: { type: integer, notnull: true }
  relations:
    HelloUser: { onDelete: CASCADE, local: id_user, foreign: id, foreignAlias: HelloBooks }
    HelloTest: { onDelete: CASCADE, local: id_test, foreign: id, foreignAlias: HelloBooks }

OK, let's open the books.yml file.
Inside, we have to specify the table for a label:

# data/fixtures/books.yml
HelloBook:
  book_1:
    name: great_book
    HelloUser: user_1

And of course, the user_1 label must be defined in the users.yml.

Example 4

You typed:

$ php symfony doctrine:build --all --no-confirmation ; php symfony doctrine:data-load

And you have this error:

$ Unknown record property / related component "0" on "HelloCommentBook"

Solution 4

This error seems to be the same as the Example 1. But it is not.
In this example we have an error of indentation.
Be careful, something like that code below is not correct:

HelloCommentBook:
  comment_book_1:
    HelloUser: user_1
    HelloMatter: matter_2
    HelloTitle: title_1
    HelloChapter: chapter_3
  text: |
    HEllo I am in the comment-books.yml file!

Where is the error?!
Let's see the correct code:

HelloCommentBook:
  comment_book_1:
    HelloUser: user_1
    HelloMatter: matter_2
    HelloTitle: title_1
    HelloChapter: chapter_3
    text: |
      HEllo I am in the comment-books.yml file!

Note where is placed the text: | line, at the same level of indentation of the table class.
You also noted that with a conjunction of 2 words in the same table, we can write the corresponding fixture file with a dash or with an underscore:

comment-books.yml

or

comment_books.yml

or even

commentbooks.yml

or why not

c-o-m_m__e-nt_bo--ok_s.yml

All are accepted!

Example 5

You typed:

$ php symfony doctrine:build --all --no-confirmation ; php symfony doctrine:data-load

And you get this error:

$   Couldn't find class HelloBook
$
$ PHP Fatal error:  Call to a member function evictAll() on a non-object in C:\site\symphony\version-1.4.12-hello\lib\plugins\sfDoctrinePlugin\lib\vendor\doctrine\Doctrine\Connection.php on line 1239
$
$ Fatal error: Call to a member function evictAll() on a non-object in C:\site\symphony\version-1.4.12-hello\lib\plugins\sfDoctrinePlugin\lib\vendor\doctrine\Doctrine\Connection.php on line 1239

Solution 5

All simply remove the books.yml file into:

data > fixtures > books.yml

If you need this file, then try to connect it with other file in the fixtures directory.

Add new comment

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.