'sqlite3.OperationalError: no such column: Transitional_Temperature
I am having trouble with some code I wrote. In the c.execute("""UPDATE MCE_Materials SET part python tells me that the tables'Transitional_Temperature' and 'Phase_Transition' do not exist. I have checked for possible typos, but I couldn't find any. Below I have listed the code. Thanks!
from tkinter import *
from PIL import ImageTk, Image
import sqlite3
root = Tk()
root.geometry("400x600")
if __name__ == "__main__":
def update():
#Databases
conn = sqlite3.connect('MCE_Materials.db')
#Create cursor
c = conn.cursor() #cursor executes a command
record_id = Delete_entry.get()
c.execute("""UPDATE MCE_Materials SET
Name_compound = :Name_compound,
Entropy = :Entropy,
Magnetisation = :Magnetisation,
Transitional_Temperature = :Transitional_Temperature,
Curie_Temperature = :Curie_Temperature,
Hysteresis = :Hysteresis,
Phase_Transition = :Phase_Transition,
Summary = :Summary
WHERE oid = :oid""",
{'Name_compound': Name_compound_editor.get(),
'Entropy': Entropy_editor.get(),
'Magnetisation': Magnetisation_editor.get(),
'Transitional_Temperature': Transitional_Temperature_editor.get(),
'Curie_Temperature': Curie_Temperature_editor.get(),
'Hysteresis': Hysteresis_editor.get(),
'Phase_Transition': Phase_Transition_editor.get(),
'Summary': Summary_editor.get(),
'oid': record_id
}) #create table and designate columns
c.execute("UPDATE ")
#Commit changes
conn.commit() #commits the changes
#close connection
conn.close() #Close connection
editor.destroy()
def Adjust():
global editor
editor = Tk()
editor.geometry("400x600")
#Databases
conn = sqlite3.connect('MCE_Materials.db')
#Create cursor
c = conn.cursor() #cursor executes a command
#record Id
record_id = Delete_entry
c.execute("SELECT * FROM MCE_Materials WHERE oid = " + record_id.get()) #Delete_Entry gets all information of 1 compound
records = c.fetchall()
#Commit changes
conn.commit() #commits the changes
#close connection
conn.close() #Close connection
global Name_compound_editor
global Entropy_editor
global Magnetisation_editor
global Transitional_Temperature_editor
global Curie_Temperature_editor
global Hysteresis_editor
global Phase_Transition_editor
global Summary_editor
global Delete_entry_editor
#Entry boxes
Name_compound_editor = Entry(editor, width = 30)
Name_compound_editor.grid(row = 0, column = 1)
Entropy_editor = Entry(editor, width = 30)
Entropy_editor.grid(row = 1, column = 1)
Magnetisation_editor = Entry(editor, width = 30)
Magnetisation_editor.grid(row = 2, column = 1)
Transitional_Temperature_editor = Entry(editor, width = 30)
Transitional_Temperature_editor.grid(row = 3, column = 1)
Curie_Temperature_editor = Entry(editor, width = 30)
Curie_Temperature_editor.grid(row = 4, column = 1)
Hysteresis_editor = Entry(editor, width = 30)
Hysteresis_editor.grid(row = 5, column = 1)
Phase_Transition_editor = Entry(editor, width = 30)
Phase_Transition_editor.grid(row = 6, column = 1)
Summary_editor = Entry(editor, width = 30)
Summary_editor.grid(row = 7, column = 1)
#Labels
Name_compound_Label_editor = Label(editor, text = "Name Compound")
Name_compound_Label_editor.grid(row = 0, column = 0, padx = 30, pady = 5)
Entropy_Label_editor = Label(editor, text = "Entropy")
Entropy_Label_editor.grid(row = 1, column = 0, padx = 30, pady = 5)
Magnetisation_Label_editor = Label(editor, text = "Magnetisation")
Magnetisation_Label_editor.grid(row = 2, column = 0, padx = 30, pady = 5)
Transitiontal_Temperature_Label_editor = Label(editor, text = "Transitional Temperature")
Transitiontal_Temperature_Label_editor.grid(row = 3, column = 0, padx = 30, pady = 5)
Curie_Temperature_Label_editor = Label(editor, text = "Curie Temperature")
Curie_Temperature_Label_editor.grid(row = 4, column = 0, padx = 30, pady = 5)
Hysteresis_Label_editor = Label(editor, text = "Hysteresis")
Hysteresis_Label_editor.grid(row = 5, column = 0, padx = 30, pady = 5)
Phase_Transition_Label_editor = Label(editor, text = "Phase Transition")
Phase_Transition_Label_editor.grid(row = 6, column = 0, padx = 30, pady = 5)
Summary_Label_editor = Label(editor, text = "Summary")
Summary_Label_editor.grid(row = 7, column = 0, padx = 30, pady = 5)
List = [Name_compound_editor, Entropy_editor, Magnetisation_editor, Transitional_Temperature_editor,
Curie_Temperature_editor, Hysteresis_editor, Phase_Transition_editor, Summary_editor]
for record in records:
for i in range(len(List)):
List[i].insert(0,record[i])
edit_Button = Button(editor, text = "Edit Changes", command = update)
edit_Button.grid(row = 8, column = 0, padx = 30, pady = 5)
#Submission change
Change_Submission_Button = Button(root, text = "Adjust compound", command = Adjust)
Change_Submission_Button.grid(row = 12, column = 0, columnspan = 2, padx = 10, pady = 10, ipadx = 100)
root.mainloop()
Edit, I forgot to add the CREATE TABLE part:
root = Tk()
root.geometry("400x600")
#Databases
conn = sqlite3.connect('MCE_Materials.db')
#Create cursor
c = conn.cursor() #cursor executes a command
c.execute("""CREATE TABLE MCE_Materials (
Name_compound text,
Entropy float,
Magnetisation float,
Transitional_Temperature float,
Curie_Temperature float,
Hysteresis float,
Phase_Transtition text,
Summary text)""") #create table and designate columns
#Commit changes
conn.commit() #commits the changes
#close connection
conn.close() #Close connection
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
