Each time I create a new migration, there are the changes I want, but there are also some changes that shouldn't be there. They are the same in each new migration.
So if I create a new migration without any changes, only those undesirable changes will be there. If I run the migration, and make a new one, those changes will be still here. I probably did something wrong, I'd like to "clean", in order to stop deleting those changes manually each time.
I'm in a project running Symfony 4.2.3 with Doctrine ORM v2.6.3, on MariaDB 10.3.14.
So here's a migration which should be empty :
final class Version20190412133855 extends AbstractMigration
{
// ...
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('ALTER TABLE player CHANGE race_id race_id INT DEFAULT NULL, CHANGE team_id team_id INT DEFAULT NULL, CHANGE country_id country_id INT DEFAULT NULL, CHANGE birthdate birthdate DATE DEFAULT NULL');
$this->addSql('ALTER TABLE clan_war CHANGE winner_id winner_id INT DEFAULT NULL');
$this->addSql('ALTER TABLE team CHANGE country_id country_id INT DEFAULT NULL, CHANGE manager manager VARCHAR(255) DEFAULT NULL, CHANGE coach coach VARCHAR(255) DEFAULT NULL, CHANGE website website VARCHAR(255) DEFAULT NULL');
$this->addSql('ALTER TABLE map CHANGE tileset_id tileset_id INT DEFAULT NULL');
$this->addSql('ALTER TABLE game CHANGE map_id map_id INT DEFAULT NULL, CHANGE winner_id winner_id INT DEFAULT NULL');
$this->addSql('ALTER TABLE game RENAME INDEX idx_7a5bc50553c55f64 TO IDX_232B318C53C55F64');
}
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('ALTER TABLE clan_war CHANGE winner_id winner_id INT DEFAULT NULL');
$this->addSql('ALTER TABLE game CHANGE map_id map_id INT DEFAULT NULL, CHANGE winner_id winner_id INT DEFAULT NULL');
$this->addSql('ALTER TABLE game RENAME INDEX idx_232b318c53c55f64 TO IDX_7A5BC50553C55F64');
$this->addSql('ALTER TABLE map CHANGE tileset_id tileset_id INT DEFAULT NULL');
$this->addSql('ALTER TABLE player CHANGE race_id race_id INT DEFAULT NULL, CHANGE team_id team_id INT DEFAULT NULL, CHANGE country_id country_id INT DEFAULT NULL, CHANGE birthdate birthdate DATE DEFAULT \'NULL\'');
$this->addSql('ALTER TABLE team CHANGE country_id country_id INT DEFAULT NULL, CHANGE manager manager VARCHAR(255) DEFAULT \'NULL\' COLLATE utf8mb4_unicode_ci, CHANGE coach coach VARCHAR(255) DEFAULT \'NULL\' COLLATE utf8mb4_unicode_ci, CHANGE website website VARCHAR(255) DEFAULT \'NULL\' COLLATE utf8mb4_unicode_ci');
}
}
All those "changes" are actually already done in the database.
There is an other small problem: the generated query ALTER TABLE game RENAME INDEX idx_7a5bc50553c55f64 TO IDX_232B318C53C55F64 which is invalid for MariaDB. If I don't delete this query, I'll get a syntax error.
And like I said: if I delete this one, the migration will run without any problems, but the same new migration will appear if I create a new one.
In an other project with the same configuration, if I make a new migration without any changes, I get an expected [WARNING] No database changes were detected.. If I make one change, I'll get just the change I want.
I maybe did something wrong in the annotations in my entities, so in case, here's one of the model (player) : https://pastebin.com/1mUPP3i3
Thanks for your help
Thanks to #rkeet:
I checked what was wrong with the Mapping and the Database with the command doc:sch:val.
Then for the RENAME INDEX syntax error case on MariaDB , I changed the server version in the Doctrine Configuration (in my case in Doctrine.yaml)
From server_version: '5.7' to server_version: mariadb-10.3.14 (check your current mariadb version with mysql --version).
Related
I created triggers after creating a database in oracle apex. When testing in SQL code everything was fine, they worked. In the application I have the Professors table and when I change the value of the column "name", in the Courses table the value of the column "professor_name" should change. However when I change the value of the column "name" in the Professors table it throws me the error.
Here is the trigger definition:
CREATE OR REPLACE TRIGGER profesori_upd
AFTER UPDATE OF ime on profesori
FOR EACH ROW
BEGIN
UPDATE kursevi set ime_profesora = :new.ime
where pr_jmbg= :new.jmbg_pr;
END;
Here is the table Proffesors:
CREATE TABLE PROFESORI( jmbg_pr VARCHAR2(13) PRIMARY KEY,
ime VARCHAR2(20) NOT NULL,
prezime VARCHAR2(20) NOT NULL,
id_spreme NUMBER(5) NOT NULL,
CONSTRAINT profesor_sprema_fk FOREIGN KEY (id_spreme) REFERENCES
STRUCNE_SPREME(id)
);
Here is the table Courses:
CREATE TABLE KURSEVI(
opis VARCHAR2(40),
id_jezik NUMBER(10) NOT NULL,
id_nivo NUMBER(10) NOT NULL,
pr_jmbg VARCHAR2(13) NOT NULL,
CONSTRAINT kurs_jezik_fk FOREIGN KEY (id_jezik) REFERENCES JEZICI(id_j),
CONSTRAINT kurs_nivo_fk FOREIGN KEY (id_nivo) REFERENCES NIVOI_KURSEVA(id_n),
CONSTRAINT kurs_profesor_fk FOREIGN KEY (pr_jmbg) REFERENCES PROFESORI(jmbg_pr),
CONSTRAINT kurs_pk PRIMARY KEY(id_jezik,id_nivo,pr_jmbg)
);
After denormalization I added columns ime_profesora and prezime_profesora to the table Courses:
ALTER TABLE KURSEVI
ADD ime_profesora VARCHAR2(20);
ALTER TABLE KURSEVI
ADD prezime_profesora VARCHAR2(20);
UPDATE KURSEVI SET ime_profesora=( SELECT ime FROM PROFESORI WHERE profesori.jmbg_pr=kursevi.pr_jmbg);
UPDATE KURSEVI SET prezime_profesora=( SELECT prezime FROM PROFESORI WHERE profesori.jmbg_pr=kursevi.pr_jmbg);
ALTER TABLE KURSEVI
MODIFY ime_profesora varchar2(20) not null;
ALTER TABLE KURSEVI
MODIFY prezime_profesora varchar2(20) not null;
Error occurs after I try to change the value of the column name in the application, it does not say what the error is.
I've created a MySQL Model with a few tables, some of them with fk's to another table. I usually export the SQL from MySQL Model to my database using the "Forward Engineer SQL CREATE Script" inside File -> Export -> Forward Engineer SQL CREATE Script. The problem here is that when I generate the creation script, all my fk's become unique. I didn't check UQ option in MySQL Model but it creates a script with unique fk's anyway, so, I need to change the SQL file generated and remove all the unwanted uniques. Anyone has a clue why this is happening?
Generated script:
CREATE TABLE IF NOT EXISTS `u514786799_detranleiloes`.`Lotes` (
`createdAt` DATE NOT NULL,
`updatedAt` DATE NOT NULL,
`id` INT UNIQUE NOT NULL AUTO_INCREMENT,
`LeiloesId` INT UNIQUE NOT NULL,
`conservado` TINYINT NULL,
`numero` INT NOT NULL,
`CRDsId` INT UNIQUE NULL,
PRIMARY KEY (`id`),
INDEX `fk_Lotes_Leiloes_idx` (`LeiloesId` ASC),
INDEX `fk_Lotes_CRDs1_idx` (`CRDsId` ASC),
CONSTRAINT `fk_Lotes_Leiloes`
FOREIGN KEY (`LeiloesId`)
REFERENCES `u514786799_detranleiloes`.`Leiloes` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_Lotes_CRDs1`
FOREIGN KEY (`CRDsId`)
REFERENCES `u514786799_detranleiloes`.`CRDs` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
AUTO_INCREMENT = 1;
CREATE TABLE dbo.Users (
id int NOT NULL IDENTITY(1,1),
uid int NOT NULL,
username nvarchar(65) NULL,
password varchar(100) NULL,
firstname nvarchar(50) NULL,
lastname nvarchar(50) NULL,
);
ALTER TABLE dbo.Users ADD CONSTRAINT PK_Users PRIMARY KEY (id, uid);
This is my sql query and want to create data model for this schema using loopback4.
Unfortunately, it doesn't seem that this feature is currently supported. An open issue tracking this feature can be found on their GitHub page here.
Using django, I added a new entry to my table. Now I want to delete it using PHPPgAdmin (postgresql), but I get No unique Identifier for this row error. What is the problem?
django automatically adds an auto-incrementing primary key, so I cannot figure out what the issue is?
I read this post, but it did not help. If you notice the image carefully, you will see that the primary key column label is id but not pk as it should be in django.
EDIT: No primary key is seen on table;
But this is what django executes;
python manage.py sql auth
CREATE TABLE "auth_user" (
"id" serial NOT NULL PRIMARY KEY,
"password" varchar(128) NOT NULL,
"last_login" timestamp with time zone NOT NULL,
"is_superuser" boolean NOT NULL,
"username" varchar(30) NOT NULL UNIQUE,
"first_name" varchar(30) NOT NULL,
"last_name" varchar(30) NOT NULL,
"email" varchar(75) NOT NULL,
"is_staff" boolean NOT NULL,
"is_active" boolean NOT NULL,
"date_joined" timestamp with time zone NOT NULL
)
;
EDIT: A screenshot from PHPPgAdmin, showing id as primary key
I think this is a bug with phpPgAdmin.
I experienced a similar problem and went directly into psql (using the command ./manage.py dbshell).
I tried deleting the row in question, and received a more helpful error message than the one from phpPgAdmin. (In my case, that the row was being referenced by another table.)
I deleted the row referenced by the other table, and was then able to delete the row in question.
This is the sql script I used to create a table in MS Access Database.
CREATE TABLE Contracts (
id int NULL DEFAULT 0,
sex varchar(255) DEFAULT 'female' NOT NULL
)
Now I want to programmatically get the default value of the field: "sex", I know it's 'female' but I don't know how to get it using C++ ADO interface.
Below is a snippet of my code:
m_pRecordset->Fields->get_Item(vIntegerType, &pvObject);
bstrColName = pvObject->GetName();
dtype = pvObject->GetType();
attr = pvObject->GetAttributes();
I can give you idea how to achieve it..
GetAttributes() method will not give you default value of the field but it will give you info about whether field is autoincrement ,system field or fixed - variable size field.
Check out for method GetDefaultValue() of the field that will do what you want.