Hello , i have two tables ,animal ,which has name,familie and weight and table food which has feed.
I want to assure that every animal has at least one food.
I did this :
import mysql.connector
from database import login_info
db=mysql.connector.Connect(**login_info)
cursor=db.cursor()
data=[('Geo','Elephant',['hay',peanuts']),
('Gerald','Gnu',['leaves','shoots']),
('Leo','Leopard',['meat'])
...................... ]
for name,familie,feed in data:
cursor.execute("""SELECT name,feed FROM animal JOIN food ON animal.id=food.anid WHERE name=%s and feed=%s""",(name,feed))
for feed in data:
cursor.execute("""SELECT COUNT(*) feed FROM food""")
food=cursor.fetchall()
db.commit()
for i in range(len(food)):
if food[i]>=1:
print("{0} "'has food'" {1}".format(name,food[i]))
else:
print("{0} "'has not food'"".format(name))
It gives me error 'failed processing format parameters' where i have 'for name,familie,feed'