Python Forum
trouble with sqlite (indentation in sql commands)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
trouble with sqlite (indentation in sql commands)
#1
hello, everybody. can someone tell me what's wrong? even trying to correct with AI doesn't work.


import sqlite3
from tkinter.constants import INSERT

conn = sqlite3.connect('test_sqlite.db')

c = conn.cursor()

 tabela3 = ('''CREATE TABLE cedido 
 (matricula INTEGER PRIMARY KEY, nome TEXT, FOREIGN KEY(cessionario_cnpj) REFERENCES cessionario(cessionario_cnpj), processo TEXT, cpf TEXT, esfera TEXT, 
 FOREIGN KEY (cessionario_nome) REFERENCES cessionario(cessionario_nome))''')

c.execute(tabela3)
the error:
Quote: File "C:\Users\vitor\Documents\pythonFiles\testing_sqlite.py", line 14
tabela3 = ('''CREATE TABLE cedido
IndentationError: unexpected indent
Reply
#2
import sqlite3
from tkinter.constants import INSERT
 
conn = sqlite3.connect('test_sqlite.db')
 
c = conn.cursor()

# next line has an extra space at the start of the line
 tabela3 = ('''CREATE TABLE cedido 
 (matricula INTEGER PRIMARY KEY, nome TEXT, FOREIGN KEY(cessionario_cnpj) REFERENCES cessionario(cessionario_cnpj), processo TEXT, cpf TEXT, esfera TEXT, 
 FOREIGN KEY (cessionario_nome) REFERENCES cessionario(cessionario_nome))''')
 
c.execute(tabela3)
This is fixed code

import sqlite3
from tkinter.constants import INSERT
 
conn = sqlite3.connect('test_sqlite.db')
 
c = conn.cursor()

tabela3 = ('''CREATE TABLE cedido 
 (matricula INTEGER PRIMARY KEY, nome TEXT, FOREIGN KEY(cessionario_cnpj) REFERENCES cessionario(cessionario_cnpj), processo TEXT, cpf TEXT, esfera TEXT, 
 FOREIGN KEY (cessionario_nome) REFERENCES cessionario(cessionario_nome))''')
 
c.execute(tabela3)
cimerio likes this post
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
Looks like there's an indentation issue in your code. Check for extra spaces or tabs before tabela3 = ('''CREATE TABLE cedido. should be aligned properly with the rest of the code.
buran write Feb-27-2025, 04:06 AM:
Spam link removed
cimerio likes this post
Reply
#4
thank you, friends
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Utilizing SQLite dot commands hammer 2 1,751 Apr-18-2022, 02:52 PM
Last Post: hammer

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020