Hi have setup a db with tables States and StoreLocations. I have created entities for both. As well as RESTful services. When posting a new Location on my local machine everything works fine.
I have deployed my project to another server and when I try to post a new Location on this machine I get the following error
Code: 23000 Message: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`vitanica`.`StoreLocation`, CONSTRAINT `storelocation_ibfk_1` FOREIGN KEY (`state_id`) REFERENCES `state` (`id`)) File: /home/audioglobe.com/zend/vendor/doctrine/dbal/lib/Doctrine/DBAL/Statement.php Line: 131 I do not understand why this would work on one machine and not another. Thanks in advance for any thoughts on the issue!
Here are my tables:
mysql> show create table StoreLocation | StoreLocation | CREATE TABLE `StoreLocation` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(60) DEFAULT NULL, `address` varchar(80) DEFAULT NULL, `city` varchar(80) DEFAULT NULL, `state_id` int(11) DEFAULT NULL, `zip` varchar(12) DEFAULT NULL, `phone` varchar(20) DEFAULT NULL, `lat` float(10,6) DEFAULT NULL, `lng` float(10,6) DEFAULT NULL, PRIMARY KEY (`id`), KEY `state` (`state_id`), CONSTRAINT `storelocation_ibfk_1` FOREIGN KEY (`state_id`) REFERENCES `state` (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=15 DEFAULT CHARSET=latin1 | mysql> show create table State | State | CREATE TABLE `State` ( `id` int(11) NOT NULL AUTO_INCREMENT, `code` varchar(10) NOT NULL, `state` varchar(255) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=51 DEFAULT CHARSET=latin1 | And a snippet from my Entities:
/** @Entity */ class State { .... /** @OneToMany(targetEntity="StoreLocation", mappedBy="state") */ private $stores; } /** @Entity @HasLifecycleCallbacks*/ class StoreLocation { /** * @ManyToOne(targetEntity="State", inversedBy="id") */ private $state; }
Stateand theStoreLocationat the same time? If not, is theStatetable populated?b0VIM 7.3�,ZP��#server/zend/routes/storelocator.phputf-8 3210#"! Utp�ghad(�g��R2 �������nP0 � � � } o j e C ! ����kMJ��^ZY#� � � � T � � � j ���(����8��� ����%$����mEC,������V����{=����});vimswapfile.