How to add integrity constraint check on all controllers while inserting values to db in YII? what is the simplest method for it?
if($model->save())
$this->redirect(array('view','id'=>$model->id));
Exception appear here
CDbCommand failed to execute the SQL statement: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '9-5' for key 'xyz'. The SQL statement executed was: INSERT INTO `tbl_table` (`xyz`, `x`, `x`, `x`, `x`, `x`, `x`, `created`) VALUES (:yp0, :yp1, :yp2, :yp3, :yp4, :yp5, :yp6, NOW())
CMysqlSchema is the class for retrieving metadata information from a MySQL database and COciSchema is the class for retrieving metadata information from an Oracle database.u can make use of the methods provided by these classes to check for the constraints for example u can make use of the method findConstraints()
Yii->app()->db->createCommand("SET FOREIGN_KEY_CHECKS=0")->execute();
execute all your sql commands/queries here
----
----
Yii->app()->db->createCommand("SET FOREIGN_KEY_CHECKS=1")->execute();
Related
I imported data into a MariaDB database while foreign key constraint checks were disabled. Those checks were enabled afterwards. However, some data in the database seems to be corrupt in the sense that the foreign key constraints are not satisfied.
I tried to use the mysqlcheck tool to verify all tables, but this does not produce any error output. Also running CHECK TABLE someTable does not show any errors or warnings.
Still I can manually show data not being correct, for example by performing a query:
select count(*) from some_table where id not in (select id from related_table)
where some_table has a foreign key constraint to related_table by id.
How do I fix this?
I try to roll back data after test runnining using:
delete from instance;
delete from workspace;
however I receive:
liquibase.exception.RollbackFailedException: liquibase.exception.DatabaseException: Referential integrity constraint violation:
"FK_INSTANCE_ID: PUBLIC.WORKSPACE FOREIGN KEY(INSTANCE_ID) REFERENCES PUBLIC.INSTANCE(ID) (1)"; SQL statement:
I figured out that it is caused by required relation beetween tables. How to force deletion.
You don't specify what database platform you are using, and the answer might differ depending on that. In general though, you need to either use a 'cascade' with delete, or else delete the relationships before deleting the tables.
I would like to know is it possible to return a DB ERROR code from trigger, rather than Custom exception created with RAISE_APPLICATION_ERROR. I have some requirement where i need to return an DB ERROR code like 1 for Unique Constraint. I have a purpose to ask this, because for some reason with some hash based partition we are not creating unique constraints on table and rather have one trigher with which i want to return Unique constraint as an error code after checking if the record exists in DB.
You can use:
RAISE DUP_VAL_ON_INDEX;
Only in this case you can't pass any arguments to this error and you will get:
ORA-00001: unique constraint (.) violated
Any one please help me out. I am syncing sql server to client using MS Sync Framework. I am getting this exception at syncOrchestrator.Synchronize();
Failed to execute the command 'BulkInsertCommand' for table ‘xyz'; the transaction was rolled back. Ensure that the command syntax is correct.
Inner Exception is:
Violation of PRIMARY KEY constraint 'PK__#B1CF471__ECD9228532A93525'. Cannot insert duplicate key in object 'dbo.#changeTable'. The duplicate key value is (0). The data for table-valued parameter \"#changeTable\" doesn't conform to the table type of the parameter. The statement has been terminated.
There is a store procedure that using above object 'dbo.#changeTable', but I don't know what to do with that??
I need to update an existing constraint in Oracle database to add a new column there.
ALTER TABLE MY_PARTNER_DETAILS
MODIFY CONSTRAINT UQ_MY_PARTNER_DETAILS
UNIQUE(PARTNER_CODE,PGOOD_CODE,SITE_CODE,PARTNER_PLACEMENT,PARTNER_PARTICIPATION)
Gives the error:
Error at line 1
ORA-00933: SQL command not properly ended
What's the problem with that?
You should drop and recreate the constraint. modify constraint allows you to change constraint's state not definition.
See: Oracle Docs