User.id and Rating.user_id must be the same type and length in order for a
foreign key to be defined between the two.
- Jon
On Thu, Oct 30, 2008 at 5:41 PM, Tobias Daur <[EMAIL PROTECTED]> wrote:
>
> Hi together,
>
> I'm not shure how to solve problems, i get, while inserting the
> generated sql.
> I'm using sf1.1 with the sfDoctrinePlugin.
>
> Snippet of my schema.yml with a 1:n relation:
> -
> User:
> actAs:
>Timestampable:
> columns:
>first_name: string(255)
>last_name: string(255)
>nick: string(255)
>password: string(255)
>street: string(255)
>postcode: string(5)
>city: string(255)
> Rating:
> columns:
>created_at: timestamp
>user_id: integer(4)
> relations:
>Users:
> class: User
> foreignAlias: Ratings
> -
>
> If i do now a
> symfony cc
> symfony doctrine:build-model
> symfony doctrine:build-sql backend
> symfony doctrine:insert-sql backend
>
> i get an error:
> -
> SQLSTATE[42000]: Syntax error or access violation: 1072 Key column
> 'user_id' doesn't exist in table. Failing Query: CREATE TABLE rating (id
> BIGINT AUTO_INCREMENT, created_at DATETIME, INDEX user_id_idx (user_id),
> PRIMARY KEY(id)) ENGINE = INNODB
> -
>
> There is no "user_id"-field in the table "rating" (wich i thought
> doctrine would add by itself), and it is impossible to produce a Index
> on a not existing field.
>
> So, i add the field to the schema:
>
> -
> User:
> actAs:
>Timestampable:
> columns:
>first_name: string(255)
>last_name: string(255)
>nick: string(255)
>password: string(255)
>street: string(255)
>postcode: string(5)
>city: string(255)
> Rating:
> columns:
>created_at: timestamp
>user_id: integer(4)
> relations:
>Users:
> class: User
> foreignAlias: Ratings
> -
>
> Now i - get an error:
> -
> SQLSTATE[HY000]: General error: 1005 Can't create table
> './fragjupp/#sql-bb2_e.frm' (errno: 150). Failing Query: ALTER TABLE
> rating ADD FOREIGN KEY (user_id) REFERENCES user(id)
> -
>
> Yes, that's right, the field "user_id" in the sql-query was already
> added:
> -
> CREATE TABLE rating (id BIGINT AUTO_INCREMENT, created_at DATETIME,
> user_id INT, INDEX user_id_idx (user_id), PRIMARY KEY(id)) ENGINE =
> INNODB;
> -
> So it can't be added as a foreign key.
>
> Now, i'm trapped. In both cases i get an error.
>
> How do I have to write my schema.yml, that this works without errors?
>
> thanks for your ideas
>
> Tobias
>
>
> >
>
--
Jonathan H. Wage
Open Source Software Developer & Evangelist
http://www.jwage.com
http://www.doctrine-project.org
http://www.symfony-project.org
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups
"symfony users" group.
To post to this group, send email to symfony-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/symfony-users?hl=en
-~--~~~~--~~--~--~---