Hi I'm new in symfony.
I'm trying to generate entities from an existing database with doctrine.
When I run this command:
php bin/console doctrine:mapping:import --force AppBundle xml
I get this exception :
[Doctrine\ORM\Mapping\MappingException]
Property "shop" in "Bug" was already declared, but it must be declared only once
I have tried to search other solutions, but I didn't find anythings.
How can I solve this problem?
This is how mysql workbench creates my table:
CREATE TABLE IF NOT EXISTS `db`.`bug` (
`id_bug` INT(11) NOT NULL AUTO_INCREMENT,
`bug_name` VARCHAR(200) NOT NULL,
`comment` VARCHAR(1000) NOT NULL,
`status` INT(11) NOT NULL DEFAULT '0',
`customer_id` VARCHAR(255) CHARACTER SET 'utf8' NOT NULL,
`shop_id` VARCHAR(255) CHARACTER SET 'utf8' NOT NULL,
`admin_id` VARCHAR(255) CHARACTER SET 'utf8' NOT NULL,
PRIMARY KEY (`id_bug`),
INDEX `fk_bug_customer1_idx1` (`customer_id` ASC),
INDEX `fk_bug_shop1_idx` (`shop_id` ASC),
INDEX `fk_bug_admin1_idx1` (`admin_id` ASC),
CONSTRAINT `fk_bug_customer1`
FOREIGN KEY (`customer_id`)
REFERENCES `db`.`customer` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_bug_shop1`
FOREIGN KEY (`shop_id`)
REFERENCES `db`.`shop` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_bug_admin1`
FOREIGN KEY (`admin_id`)
REFERENCES `db`.`admin` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1;
I'm working in symfony 3.3, mysql and php7.
Thanks.
There were two problem:
First of all there was a relaction duplicated on the same enitity
It was not the only problem. We noticed that in doctrine occours problems when there is a primary key that is also a foreign key, so we added a new field id for the primary key.
Related
I am seeing the error below when I run the following query inside a Doctrine migration:
ALTER TABLE crmpicco_course_version DROP FOREIGN KEY FK_C060B146DE13F470
Migration 20151209153121 failed during Execution.
Error An exception occurred while executing
'ALTER TABLE crmpicco_course_version DROP FOREIGN KEY FK_C060B146DE13F470':
SQLSTATE[HY000]: General error:
1025 Error on rename of './crmpicco_dev/crmpicco_course_version'
to './crmpicco_dev/#sql2-77c-b0a' (errno: 152)
This is the table I am trying to change:
CREATE TABLE `crmpicco_course_version` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`course_id` int(11) NOT NULL,
`updated_by_id` int(11) DEFAULT NULL,
`name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`start_date` datetime DEFAULT NULL,
`end_date` datetime DEFAULT NULL,
`created_at` datetime NOT NULL,
`updated_at` datetime NOT NULL,
PRIMARY KEY (`id`),
KEY `IDX_C060B146896DBBDE` (`updated_by_id`),
KEY `IDX_C060B146DE13F470` (`course_id`),
CONSTRAINT `FK_C060B146896DBBDE` FOREIGN KEY (`updated_by_id`) REFERENCES `crmpicco_user` (`id`),
CONSTRAINT `FK_C060B146DE13F470` FOREIGN KEY (`course_id`) REFERENCES `crmpicco_course` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
What is preventing me from dropping this foreign key successfully?
When I run SHOW ENGINE INNODB STATUS I get the following:
------------------------
LATEST FOREIGN KEY ERROR
------------------------
151209 16:25:42 Error IN dropping of a FOREIGN KEY CONSTRAINT of TABLE "crmpicco_dev"."crmpicco_course_version",
IN SQL command
ALTER TABLE crmpicco_course_version DROP FOREIGN KEY FK_C060B146DE13F470
Cannot find a CONSTRAINT WITH the given id "FK_C060B146DE13F470".
After endless dropping and recreating of my local database I found that this was caused by Doctrine creating the same ALTER statement more than once and also in the wrong order.
I had to change the statements around manually to make sure I migrated data from my old table to my new table before creating the new foreign key constraint on the new table. Without this change I was getting the error above and others.
I ran into troubles when I want to add new column mapped ONE TO ONE. It creates unique index on that column and while executing SQL it obviously fail, because that table already contains rows. It's not a problem to remove data in development database, but it will be in a production db.
This is how the SQL looks like:
$this->addSql('CREATE TABLE program_settings (id INT AUTO_INCREMENT NOT NULL, booking_cancel VARCHAR(155) NOT NULL, booking_ahead VARCHAR(155) NOT NULL, created_at DATETIME NOT NULL, modified_at DATETIME NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB');
$this->addSql('ALTER TABLE program ADD settings_id INT NOT NULL AFTER studio_id');
$this->addSql('ALTER TABLE program ADD CONSTRAINT FK_92ED778459949888 FOREIGN KEY (settings_id) REFERENCES program_settings (id)');
$this->addSql('CREATE UNIQUE INDEX UNIQ_92ED778459949888 ON program (settings_id)');
What should I do in that case?
I think the problem could be from your NOT NULL constraint on the settings_id column.
You have to:
Add you foreign key (settings_id) without the NOT NULL constraint
Update all your foreign fields (settings_id) with values
ALTER your foreign key (settings_id) with NOT NULL constraint
I have a database that i want to do some reverse engineering to tables using doctrine 2, so i used this simple commands
php app/console doctrine:mapping:import --force ProjectBundle yml
php app/console doctrine:mapping:convert annotation ./src
php app/console doctrine:generate:entities ProjectBundle
but the problem doctrine did not reverse engineered one join table containing two foreign keys but it did for another.
here you will find an sql statements for creating the two join tables the first have been reverse engineered the last one not
CREATE TABLE IF NOT EXISTS `control`.`project_problem_place` (
`id_place` INT(11) NOT NULL,
`id_problem` INT(11) NOT NULL,
`id_project` INT(11) NOT NULL,
PRIMARY KEY (`id_place`, `id_problem`, `id_project`),
INDEX `FK_project1` (`id_project` ASC),
INDEX `FK_problem1` (`id_problem` ASC),
CONSTRAINT `FK_problem1`
FOREIGN KEY (`id_problem`)
REFERENCES `control`.`problem` (`id`),
CONSTRAINT `FK_project1`
FOREIGN KEY (`id_project`)
REFERENCES `control`.`project` (`id`),
CONSTRAINT `FK_place1`
FOREIGN KEY (`id_place`)
REFERENCES `control`.`place` (`id`))
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1;
CREATE TABLE IF NOT EXISTS `control`.`project_code` (
`id_project` INT(11) NOT NULL,
`id_code` INT(11) NOT NULL,
PRIMARY KEY (`id_project`, `id_code`),
INDEX `FK_CODE2` (`id_code` ASC),
CONSTRAINT `FK_PROJECT2`
FOREIGN KEY (`id_project`)
REFERENCES `control`.`project` (`id`),
CONSTRAINT `FK_CODE2`
FOREIGN KEY (`id_code`)
REFERENCES `control`.`code` (`id`))
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1;
Thank you.
I am a newbie to PHP. I have been given the code snippet below as homework:
CREATE TABLE `admin_log` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`statusdate` DATETIME DEFAULT NULL,
`type` INT(11) DEFAULT NULL
PRIMARY KEY (`id`)
) ENGINE=MYISAM AUTO_INCREMENT=1 DEFAULT CHARSET=latin
Why will it not be possible to set up any foreign key constraints using this table?
I have done some research on Google and I cant find a reason why foreign key constraints are not possible. Please help
You can do that like this :
CREATE TABLE `admin_log` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`statusdate` DATETIME DEFAULT NULL,
`type` INT(11) DEFAULT NULL,
INDEX (type),
FOREIGN KEY (type)
REFERENCES type(id)
ON UPDATE CASCADE ON DELETE RESTRICT,
PRIMARY KEY (`id`)
) ENGINE=INNODB AUTO_INCREMENT=1 DEFAULT CHARSET=latin
Notice the engine INNODB insetad of MYISAM which doesn't permit foreign key.
Or using MySQLAdmin in the "structure" tab, click on the "relationals view" link below the table description.
Even it has been mentioned on comment before -- just to make it more prominent: MyISAM is not supporting foreign keys. So you will need to change the engine of your table to e.g. INNODB if possible.
When I try and create a user, it goes to a blank white page. When I go back to crm, no user was created. Is there a fix?
so for example there was another issue where webforms did not want to save. so i applied a fix i found somewhere which was to add a database table. the code for that is below. so i was looking for similar help with this new issue above. don't know if it's going to be a mysql modification or a php modification, but hopefully someone knows something.
CREATE TABLE `vtiger_webforms_field` (
`id` int(19) NOT NULL AUTO_INCREMENT,
`webformid` int(19) NOT NULL,
`fieldname` varchar(50) NOT NULL,
`neutralizedfield` varchar(50) NOT NULL,
`defaultvalue` varchar(200) DEFAULT NULL,
`required` int(10) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
KEY `webforms_webforms_field_idx` (`id`),
KEY `fk_1_vtiger_webforms_field` (`webformid`),
KEY `fk_2_vtiger_webforms_field` (`fieldname`),
CONSTRAINT `fk_1_vtiger_webforms_field` FOREIGN KEY (`webformid`) REFERENCES `vtiger_webforms` (`id`) ON DELETE CASCADE,
CONSTRAINT `fk_3_vtiger_webforms_field` FOREIGN KEY (`fieldname`) REFERENCES `vtiger_field` (`fieldname`) ON DELETE CASCADE
)