Spatne urceny primary index pri selectu po insertu
- karfi
- Člen | 21
Ahoj, v tabulce kurzyVse, do ktere vkladam data mam jako primarni klic kurzId, auto increment. Do teto tabulky vlozim data (skutecne tam jsou) pomoci table->insert(). Pri vkladani vsak skoncim s chybou: SQLSTATE[42S22]: Column not found: 1054 Unknown column ‚kurzyVse.id‘ in ‚where clause‘, ktera je podle me zpusobena tim, ze Nette pri automatickem selectu po insertu uvazuje jako primarni klic id, coz nechapu proc. Jde nekde nastavit, jaky primarni klic ma nette uvazovat? Dik.
- karfi
- Člen | 21
Config mam takto:
courses:
dsn: 'mysql:host=localhost;dbname=courses'
user: username
password: password
reflection: discovered
Dotaz pro vlozeni:
$insertCommon = $coursesAllTable->insert(array(
'courseName' => $courseName,
'coursePlace' => $coursePlace,
'courseStart' => \DateTime::createFromFormat ( 'j.n.Y', $courseStart ),
'courseEnd' => \DateTime::createFromFormat ( 'j.n.Y', $courseEnd ),
'startLogging' => \DateTime::createFromFormat ( 'j.n.Y', $startLogging ),
'courseCapacity' => $courseCapacity,
'cashInfo' => $cashInfo,
'maturity' => \DateTime::createFromFormat ( 'j.n.Y', $maturity ),
'moreInfo' => $moreInfo,
'filePath' => $infoFile,
'contactPhone' => $contactPhone,
'courseCreated' => new \DateTime(),
'active' => '0',
'adminId' => $creator,
'typeId' => $typeId
));
Vygenerovane dotazy:
Vlozeni:
INSERT INTO `coursesAll` (`courseName`, `coursePlace`, `courseStart`, `courseEnd`, `startLogging`,
`courseCapacity`, `cashInfo`, `maturity`, `moreInfo`, `filePath`, `contactPhone`, `courseCreated`,
`active`, `adminId`, `typeId`)
VALUES ('pokus 190405', 'klasik', '2014-09-01 19:04:31', '2015-10-01 19:04:31', '2014-09-01 19:04:31',
5, 'adfs', '2014-10-01 19:04:31', 'qwer', NULL, '789654123', '2014-09-22 19:04:31', '0', 'admin',
1)
a zaroven select:
SELECT *
FROM `coursesAll`
WHERE (`coursesAll`.`id` = '58')
Struktura tabulky coursesAll je:
Column Type Comment
courseId int(11) Auto Increment
courseName varchar(100)
coursePlace varchar(100)
courseStart date
courseEnd date
courseCapacity int(11)
startLogging date
endLogging datetime
maturity date NULL
cashInfo varchar(300) NULL
contactPhone varchar(20) NULL
moreInfo text NULL
filePath varchar(200) NULL
courseCreated datetime
adminId varchar(20)
typeId int(11)
active tinyint(1)
partListAdd varchar(200)
partListCreated datetime
PRIMARY courseId
Cache jsem po zmene configu smazal.
- David Matějka
- Moderator | 6445
jakou mas verzi nette? posli prosim sql dump struktury tabulky, ja to kdyztak zkusim u sebe..
- karfi
- Člen | 21
DROP TABLE IF EXISTS `coursesAll`;
CREATE TABLE `coursesAll` (
`courseId` int(11) NOT NULL AUTO_INCREMENT,
`courseName` varchar(100) COLLATE utf8_czech_ci NOT NULL,
`coursePlace` varchar(100) COLLATE utf8_czech_ci NOT NULL,
`courseStart` date NOT NULL,
`courseEnd` date NOT NULL,
`courseCapacity` int(11) NOT NULL,
`startLogging` date NOT NULL,
`endLogging` datetime NOT NULL,
`maturity` date DEFAULT NULL,
`cashInfo` varchar(300) COLLATE utf8_czech_ci DEFAULT NULL,
`contactPhone` varchar(20) COLLATE utf8_czech_ci DEFAULT NULL,
`moreInfo` text COLLATE utf8_czech_ci,
`filePath` varchar(200) COLLATE utf8_czech_ci DEFAULT NULL,
`courseCreated` datetime NOT NULL,
`adminId` varchar(20) COLLATE utf8_czech_ci NOT NULL,
`typeId` int(11) NOT NULL,
`active` tinyint(1) NOT NULL,
`partListAdd` varchar(200) COLLATE utf8_czech_ci NOT NULL,
`partListCreated` datetime NOT NULL,
PRIMARY KEY (`courseId`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci;
verze nette je 2.2.3
- David Matějka
- Moderator | 6445
funguje mi to..
jeste me napada, nedelas nekde neco jako
$context = new \Nette\Database\Context($connection);
?
- karfi
- Člen | 21
Dobre.. Muzu se jen zeptat, proc je to spatne? Vim, ze jsem to tam puvodne mel a neco mi pak nefungovalo, takze jsem to kvuli tomu upravil na to Connection.
Ted dostavam chybu ze chce ten Context a ja mu davam Connection- kde to prosimte zmenim, abych mu daval Context?
Editoval karfi (22. 9. 2014 21:56)
- David Matějka
- Moderator | 6445
protoze context zaregistrovany v DI kontejeru prave obsahuje spravnou reflection apod.
Ted dostavam chybu ze chce ten Context a ja mu davam Connection- kde to prosimte zmenim, abych mu daval Contex
zmenis typehint a dle tvych predchozich prispevku to vypada, ze pouzivas vice
databazi, ze? takze v neonu mas neco jako @nette.database.courses
?
tak to zmen na @nette.database.courses.context