Nettrine migration nefunguje mapping
- Majksa
- Člen | 17
Ahoj,
poradil by mi někdo prosím, proč mi nefunguje mapping u migrací?
Chtěl bych migrovat Usera, ale vygeneruje se mi vždy jen
VARCHAR(255)
.
Verze Nette je 3.0
Composer require
{
"php": ">=7.1",
"contributte/console": "^0.8.0",
"dg/adminer-custom": "^1.8",
"latte/latte": "^2.5",
"nette/application": "^3.0",
"nette/bootstrap": "^3.0",
"nette/caching": "^3.0",
"nette/database": "^3.0",
"nette/di": "^3.0",
"nette/finder": "^2.5",
"nette/forms": "^3.0",
"nette/http": "^3.0",
"nette/mail": "^3.0",
"nette/robot-loader": "^3.0",
"nette/safe-stream": "^2.4",
"nette/security": "^3.0",
"nette/utils": "^3.0",
"nettrine/annotations": "^0.6.2",
"nettrine/cache": "^0.2.0",
"nettrine/dbal": "^0.6.4",
"nettrine/fixtures": "^0.5.2",
"nettrine/migrations": "^0.6.2",
"nettrine/orm": "^0.7.0",
"php-curl-class/php-curl-class": "^8.8",
"restcord/restcord": "^0.4.0",
"tracy/tracy": "^2.6"
}
Config
extensions:
console: Contributte\Console\DI\ConsoleExtension(%consoleMode%)
nettrine.annotations: Nettrine\Annotations\DI\AnnotationsExtension
nettrine.cache: Nettrine\Cache\DI\CacheExtension
nettrine.migrations: Nettrine\Migrations\DI\MigrationsExtension
nettrine.fixtures: Nettrine\Fixtures\DI\FixturesExtension
nettrine.dbal: Nettrine\DBAL\DI\DbalExtension
nettrine.dbal.console: Nettrine\DBAL\DI\DbalConsoleExtension
nettrine.orm: Nettrine\ORM\DI\OrmExtension
nettrine.orm.cache: Nettrine\ORM\DI\OrmCacheExtension
nettrine.orm.console: Nettrine\ORM\DI\OrmConsoleExtension(%consoleMode%)
nettrine.orm.annotations: Nettrine\ORM\DI\OrmAnnotationsExtension
nettrine.orm:
configuration:
autoGenerateProxyClasses: %debugMode%
nettrine.orm.annotations:
mapping:
App\Model\Entity: %appDir%/Model/Entity
nettrine.orm.cache:
defaultDriver: Doctrine\Common\Cache\PhpFileCache("%tempDir%/cache/nettrine.cache")
nettrine.migrations:
directory: %appDir%/../db/Migrations
nettrine.fixtures:
paths:
- %appDir%/../db/Fixtures
User Entity
<?php
namespace App\Model\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="user")
*/
class UserEntity
{
/**
* @ORM\Id
* @ORM\Column(type="string", length=18)
*/
public string $id_user;
/**
* @ORM\Column(type="string", length=32)
*/
public string $username;
/**
* @ORM\Column(type="string", length=4)
*/
public string $discriminator;
/**
* @ORM\Column(type="string", length=34, nullable=true)
*/
public string $avatar;
/**
* @ORM\Column(type="string", length=320, unique=true)
*/
public string $email;
/**
* @ORM\Column(type="string", length=32)
*/
public string $access_token;
}
Vygenerovaná migrace
<?php
declare(strict_types=1);
namespace Database\Migrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20200719190341 extends AbstractMigration
{
public function getDescription() : string
{
return '';
}
public function up(Schema $schema) : void
{
// this up() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
$this->addSql('CREATE TABLE user (id_user VARCHAR(255) NOT NULL, username VARCHAR(255) NOT NULL, discriminator VARCHAR(255) NOT NULL, avatar VARCHAR(255) NOT NULL, email VARCHAR(255) NOT NULL, access_token VARCHAR(255) NOT NULL, PRIMARY KEY(id_user)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB');
}
public function down(Schema $schema) : void
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
$this->addSql('DROP TABLE user');
}
}
Editoval Majksa (19. 7. 2020 21:19)
- Mistrfilda
- Člen | 76
Ahoj,
zkusil jsem to ted u sebe na aktualnich migrations a dbal. Me to funguje a vygenerovalo se to spravne.
Zkus prosim smazat cache a pustit schema tool, jestli se to vygeneruje spravne tam
bin/console orm:schema-tool:update --dump-sql
- Majksa
- Člen | 17
díky za odpověď,
cache smazána a tady je output z schema toolu
The following SQL statements will be executed:
DROP INDEX email ON user;
ALTER TABLE user CHANGE id_user id_user VARCHAR(255) NOT NULL, CHANGE username username VARCHAR(255) NOT NULL, CHANGE discriminator discriminator VARCHAR(255) NOT NULL, CHANGE avatar avatar VARCHAR(255) NOT NULL, CHANGE email email VARCHAR(255) NOT NULL, CHANGE access_token access_token VARCHAR(255) NOT NULL;
takže se to pořád generuje špatně…
Editoval Majksa (19. 7. 2020 23:13)
- Mistrfilda
- Člen | 76
rad bych pomohl ale nedari se mi to zreplikovat u sebe. uz me jen napada, jakou verzi mysql pouzivas a pouzivas defaultni driver pro doctrine (resp. nastavujes nekde dale sekci driver u dbal->connection)?
- Mistrfilda
- Člen | 76
Napadlo me to, ale jestli pouzivas pdo_mysql
, tak tim to neni,
pouzivam stejny. Kazdopadne to neni problem migraci ale toho, ze doctrine dbal
uz to tak generuje, kdyz to vraci i schema-tool. Bohuzel me uz nic nenapada.
Jeste se muzes zkusit zeptat na slacku pehapkaru (https://pehapkari.slack.com/…FmXeKiL21fXQ#/) – je tam
primo roomka pro doctrine nebo contributte.
Editoval Mistrfilda (20. 7. 2020 9:49)
- Majksa
- Člen | 17
Omlouvám se za pozdní odpověď a posílám output:
------------------------------- -----------------------------
Field Value
------------------------------- -----------------------------
Name App\Model\Entity\UserEntity
Root entity name App\Model\Entity\UserEntity
Custom generator definition None
Custom repository class None
Mapped super class? False
Embedded class? False
Parent classes Empty
Sub classes Empty
Embedded classes Empty
Named queries Empty
Named native queries Empty
SQL result set mappings Empty
Identifier [
"id_user"
]
Inheritance type 1
Discriminator column None
Discriminator value None
Discriminator map Empty
Generator type 5
Table {
"name": "user"
}
Composite identifier? False
Foreign identifier? False
Sequence generator definition None
Table generator definition None
Change tracking policy 1
Versioned? None
Version field None
Read only? False
Entity listeners Empty
Association mappings:
Field mappings:
id_user
fieldName id_user
type string
scale Empty
length Null
unique False
nullable False
precision Empty
id True
columnName id_user
username
fieldName username
type string
scale Empty
length Null
unique False
nullable False
precision Empty
columnName username
discriminator
fieldName discriminator
type string
scale Empty
length Null
unique False
nullable False
precision Empty
columnName discriminator
avatar
fieldName avatar
type string
scale Empty
length Null
unique False
nullable False
precision Empty
columnName avatar
email
fieldName email
type string
scale Empty
length Null
unique False
nullable False
precision Empty
columnName email
access_token
fieldName access_token
type string
scale Empty
length Null
unique False
nullable False
precision Empty
columnName access_token
------------------------------- -----------------------------