I've fresh isntall of Symfony 1.4 with Doctrine ORM.
I'm looking to install the plugin sfDoctrineGuard. I followed the instructions here:
http://www.symfony-project.org/plugins/sfDoctrineGuardPlugin
all works fine until this step:
symfony doctrine:insert-sql
when I get an error:
SQLSTATE[HY000]: General error: 1005 Can't create table 'kickboxing.#sql-2b5b_a8f' (error 150) Failing Query "ALTER TABLE profile ADD CONSTRAINT profile_sf_guard_user_id_sf_guard_user_id FOREIGN KEY (sf_guard_user_id) REFERENCES sf_guard_user(id)
It did seem to create some tables:
profile
sf_guard_forgot_password
sf_guard_group
sf_guard_group_permission
sf_guard_permission
sf_guard_remember_key
sf_guard_user
sf_guard_user_group
sf_guard_user_permission
any ideas?
UPDATE:
I'm after spotting this really has nothign to do with doctrine/symfony. The issue seems to be with mysql I ran the alter command above in MySQL and of course I get same error.
For reference on that I've Debian Squeeze installed and mysql 5.
UPDATE2 :
when i run
SHOW INNODB STATUS;
I get
LATEST FOREIGN KEY ERROR
110927 7:58:35 Error in foreign key constraint of table _kickboxing/#sql-2b5b_a86:
FOREIGN KEY (sf_guard_user_id) REFERENCES sf_guard_user(id):
Cannot find an index in the referenced table where the
referenced columns appear as the first columns, or column types
in the table and the referenced table do not match for constraint.
Note that the internal storage type of ENUM and SET changed in
tables created with >= InnoDB-4.1.12, and such columns in old tables
cannot be referenced by such columns in new tables.
See http://dev.mysql.com/doc/refman/5.1/en/innodb-foreign-key-constraints.html
for correct foreign key definition.
Looks like a mySql issue. You can get a full (better) description of the error by logging into the mysql console and running
show innodb status
then look for the LATEST FOREIGN KEY ERROR to get an idea of what went wrong
I am using Symfony 1.4.16 and to configure sfDoctrineGuardPlugin, I followed prettyscripts.com but the schema.yml should be as follows;
Note: user_id is integer(8) thats what the size of sf_guard's id column type is.
sfGuardUserProfile:
tableName: sf_guard_user_profile
actAs: { Timestampable: ~ }
options: { collate: utf8_unicode_ci, charset: utf8 }
columns:
id: { type: integer(8), primary: true, autoincrement: true }
user_id: { type: integer(8), notnull: true }
fullname: { type: string(80) }
email: { type: string(100) }
relations:
User:
class: sfGuardUser
foreign: id
local: user_id
type: one
onDelete: cascade
foreignType: one
foreignAlias: Profile
Related
I am using the following orm description:
App\Entity\Journal:
type: entity
table: hpa_journal
repositoryClass: App\Repository\JournalRepository
id:
id:
type: integer
id: true
generator:
strategy: AUTO
fields:
longDescription:
type: array
nullable: true
column: long_description
When I run a doctrine:schema:create it has no problems at all and creates the DB.
But, when I run a schema:update I get the following error:
php bin/console doctrine:schema:update --dump-sql
The following SQL statements will be executed:
ALTER TABLE HPA_JOURNAL MODIFY (long_description CLOB DEFAULT NULL);
Which makes no sense since the CLOB is already as DEFAULT NULL, doctrine made it that way with the schema:create
When I run the schema:update --force to get rid of the message, I get the ORACLE error:
ORA-22859: invalid modification of columns
When doctrine compares the DB and the model it triggers a problem since in the DB the types "text", "array", "json_array",... are just CLOBS.
In order to really make the difference you must add (if not made automatically like in my case) a proper comment:
COMMENT ON COLUMN HPA_JOURNAL.LONG_DESCRIPTION IS '(DC2Type:array)'
I add two tables to db with this schema:
Receiptjob:
columns:
charity_id: integer
sf_guard_user_id: integer
created_at: timestamp
finished_at: timestamp
job_type: string(32)
job_status: integer
relations:
User:
class: sfGuardUser
Charity:
class: Charity
Spende:
class: Spende
refClass: ReceiptjobMap
type: many
local: receiptjob_id
foreign: spenden_id
ReceiptjobMap:
columns:
receiptjob_id: integer
spenden_id: integer
spenden_recurring: string(32)
relations:
Receiptjob:
class: Receiptjob
local: receiptjob_id
foreign: id
onDelete: CASCADE
Spende:
class: Spende
local: spenden_id
Everything works fine, untill i start my docker container this morning. I get allways this error message:
Uncaught Error: Call to a member function setTableName() on null in /var/www/vendor/lexpress/doctrine1/lib/Doctrine/Record/Abstract.php:140
I'll try to fix error but nothings helps, at least i build a new branch, added my schema.yml again an migrate it, but the error still alive....
what i'm doing wrong?
In my case, i was the problem, because i do not call parent::_construct in my class because in the BaseClass was no __construct. But BaseClass extented sfDoctrineRecord, and there is a __construct. So this was the reaseon while setTableName runs on null.
I have a problem with a symfony 1.4 setup :
I created the schema.yml:
BlogCategory:
actAs: { Timestampable: ~ }
columns:
name: { type: string(255), notnull: true, unique: true }
BlogPost:
actAs: { Timestampable: ~ }
columns:
category_id: { type: integer, notnull: true }
title: { type: string(255), notnull: true }
body: { type: string(255), notnull: true }
relations:
BlogCategory: { onDelete: CASCADE, local: category_id, foreign: id, foreignAlias: BlogPosts }
(based on jobeet tutorial )
then it generated me the table schema.sql :
CREATE TABLE blog_category (id INTEGER PRIMARY KEY AUTOINCREMENT, name VARCHAR(255) NOT NULL UNIQUE, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL);
CREATE TABLE blog_post (id INTEGER PRIMARY KEY AUTOINCREMENT, category_id INTEGER NOT NULL, title VARCHAR(255) NOT NULL, body VARCHAR(255) NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL);
which seems right to me.
And to finish I tried to add fixtures and load the data, my fixtures are as follows:
data/fixtures/categories.yml:
BlogCategory:
design:
name: Design
programming:
name: Programming
management:
name: Management
administrator :
name: Administrator
data/fixtures/posts.yml
BlogPost:
initial_post_1:
BlogCategory : design
title: Initial post 1
body: This post is an initial test number 1
initial_post_2:
BlogCategory : design
title: Initial post 2
body: This post is an initial test number 2
The php symfony doctrine:data-load command is generating me the categories but not the posts, so I tried :
php symfony doctrine:data-load data/fixtures/posts.yml
Invalid row key specified: (blog_category) design, referred to in
(blog_post) initial_post_1
Any idea why I can't laod the posts ? I've already tried to delete the db re-generate etc...
Okey so after many tests and git reset --hard HEAD to fix my datas, it seems that I had a problem with my BlogPost.class.php which contained an empty save() method override that was messing things up.
Plus, to rewrite data in the right way the command to use is:
php symfony doctrine:build --all --and-load
and not :
php symfony doctrine:data-load
Hope it could help anyone with the same problem !
I'm trying to model a user which could be invited by another user. So I set up one-to-many self reference in my doctrine model.
User:
tableName: users
actAs:
Timestampable:
columns:
id:
type: integer(11)
primary: true
autoincrement: true
name:
type: string(255)
unique: true
password:
type: string(255)
email:
type: string(255)
[...]
invited_by:
type: integer(11)
relations:
Inviter:
class: User
type: one
local: invited_by
foreign: id
foreignAlias: Invitees
onDelete: SET NULL
onUpdate: CASCADE
options:
type: InnoDB
collate: utf8_unicode_ci
charset: utf8
This works just fine in MySQL, but if I try to save the record using the User objects save()-method in Postgres the following error is thrown:
SQLSTATE[42P01]: Undefined table: 7 FEHLER: Relation »users_id«
existiert nicht LINE 1: SELECT CURRVAL('users_id') ^. Failing Query:
"SELECT CURRVAL('users_id')"
I think it is something related to the self reference, but I can't find a mistake in my modeling. Anyone an idea on this?
The default name of a sequence attached to a serial column is tablename_colname_seq
currval is for retrieving the "current value" of a sequence.
So it would have to be:
SELECT currval('users_id_seq')
Your whole syntax is obviously made out for MySQL. Things like type: InnoDB, integer(11) or autoincrement don't make sense in Postgres.
Let's say that I have YAML scheme looking like that :
Note:
options:
type: MyISAM
collate: utf8_unicode_ci
charset: utf8
actAs: { Timestampable: ~ }
columns:
content: { type: string, notnull: true}
order_id: int(5)
user_id : int
relations:
User:
foreignAlias: Notes
local: user_id
foreign: id
type: one
foreignType: man
onDelete: CASCADE
When performing :
$note->setOrderId(0);
$note->save();
I'm getting the following error :
1 validator failed on order_id (type)
MySQL store order_id as bigint(20).
I am using Ubuntu 9.10, Symfony 1.2, PHP 5 and MySQL 5.
EDIT :
Got a hint, if I remove all mention of the size in the YAML file, I get a second validator error for order_id (lenght) :-)
I got it. Replacing "int" by "integer" and getting rid of the size did the trick. Now the YAML file looks like :
Note:
options:
type: MyISAM
collate: utf8_unicode_ci
charset: utf8
actAs: { Timestampable: ~ }
columns:
content: { type: string, notnull: true}
order_id: integer
user_id : integer
relations:
User:
foreignAlias: Notes
local: user_id
foreign: id
type: one
foreignType: man
onDelete: CASCADE
I tried that because other people on the net had similar errors, solved replacing "varchar" with "string".
If someone get stuck into that and read this answer, have a beer in their names :-)
I know this is old...
I just thought I might clarify that valid doctrine types are "integer", "string", "float", "decimal", "object", "clob", "blob", "enum", "array".
Doctrine then translates the doctrine type into the correct database type for the chosen backend.
Thats why "int" failed the type validator, but "integer" works.