This is an automated archive.
The original was posted on /r/mysql by /u/AdVast6607 on 2023-08-15 11:32:48+00:00.
This is my table
CREATE TABLE IF NOT EXISTS ContractDetails (
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
ContractName VARCHAR(255) NOT NULL,
Time DATETIME NOT NULL,
FundingRate DECIMAL(10, 10) NOT NULL,
CurrencyID INT UNSIGNED NOT NULL,
ContractID INT UNSIGNED NOT NULL,
PRIMARY KEY (id), CONSTRAINT uc_contract_details UNIQUE (ContractName, Time, CurrencyID),
FOREIGN KEY (CurrencyID) REFERENCES Currency(id),
FOREIGN KEY (ContractID) REFERENCES Contract(id)
);
This is the code that I am trying to run.
try:
query = f"INSERT INTO ContractDetails (ContractName, Time, FundingRate, CurrencyID, ContractID) VALUES ('{name}', '{time}', {funding_rate},{currency_id}, {contract_id})"
cursor.execute(query)
except IntegrityError:
print('not unique')
I checked in MySql client whether there were duplicates, but it returned an empty set. Why is it happening?
SELECT * FROM ContractDetails
WHERE ContractName = 'PERP Perpetual/USDT' AND
Time = '2023-08-15 04:00:00' AND
FundingRate = 0.0001 AND
CurrencyID = 1 AND
ContractID = 116;
I have 242551 rows in the table. I am making a web scraper. It does not get stuck in a specific part. It happens randomly. Sometimes it gets this error and sometimes it doesn’t.
You must log in or # to comment.