Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > fr.comp.lang.python > #3661
| Path | csiph.com!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!news.uzoreto.com!border1.nntp.ams1.giganews.com!nntp.giganews.com!buffer1.nntp.ams1.giganews.com!buffer2.nntp.ams1.giganews.com!news.giganews.com.POSTED!not-for-mail |
|---|---|
| NNTP-Posting-Date | Fri, 03 Dec 2021 04:58:25 -0600 |
| Newsgroups | fr.comp.lang.python |
| Subject | Fonction Python et MySQL, pour créer une clé étrangère |
| X-poster | PEAR::Net_NNTP v1.5.0 (stable) |
| From | Olivier92410 <nospam_olivier.debeyssac@gmail.com.invalid> |
| Content-Type | text/plain; charset=windows-1252 |
| Content-Transfer-Encoding | 8bit |
| Organization | !No_Organization! |
| Message-ID | <CAOdnZ2m4f_MZTT8nZ2dnUU7983NnZ2d@giganews.com> (permalink) |
| Date | Fri, 03 Dec 2021 04:58:25 -0600 |
| Lines | 31 |
| X-Usenet-Provider | http://www.giganews.com |
| X-Trace | sv3-WzgADHnbmGpAEXknA9UX13Y8qjefR7E9U1wCrxhJMXmE+VyNrUllbnH1KYsU2US4Pvs+d/7om0iqklK!y1tAddumZShJI5HNsMzEbPJuY6CJunhxLiWF4JM4GhvjWejlqM1oefl0/dw/Hq4f0p3hSW0+pZDm |
| X-Complaints-To | abuse@giganews.com |
| X-DMCA-Notifications | http://www.giganews.com/info/dmca.html |
| X-Abuse-and-DMCA-Info | Please be sure to forward a copy of ALL headers |
| X-Abuse-and-DMCA-Info | Otherwise we will be unable to process your complaint properly |
| X-Postfilter | 1.3.40 |
| X-Original-Lines | 30 |
| X-Original-Bytes | 2309 |
| Xref | csiph.com fr.comp.lang.python:3661 |
Show key headers only | View raw
Bonjour, Je veux insérer dans plusieurs tables une clé étrangère.
Pour cela, j'ai créé un dictionnaire qui fournira à une fonction les paramètres
nécessaires à la création de ces clés.
Ci-dessous, une partie du dictionnaire utilisé, pour rester simple:
d_fk = {'Bien_Immo': ['fk_Id_Lot', 'Lot', 'Id']}
Puis la fonction,
def create_fk(name1, name2, name3, name4):
url = "e;mysql+pymysql://{user}:{password}@localhost/{db}"e;
engine = create_engine(url.format(user='root', password='Fer458it',
db='data_immo'))
engine.execute(f"e;ALTER TABLE {name1}"e;
f"e;ADD COLUMN {name2},"e;
f"e;ADD CONSTRAINT {name2}"e;
f"e;ADD FOREIGN KEY ({name2}) REFERENCES {name3}({name4})"e;
f"e;ON DELETE CASCADE"e;)
return
for key in d_fk.keys():
if isinstance(d_fk[key][0], list):
for i in range(len(d_fk[key])):
[n2, n3, n4] = [d_fk[key][i][0], d_fk[key][i][1], d_fk[key][i][2]]
create_fk(key, n2, n3, n4)
else:
[n2, n3, n4] = [d_fk[key][0], d_fk[key][1], d_fk[key][2]]
create_fk(key, n2, n3, n4)
Ce code retourne une erreur de syntaxe 1064,
Si vous avez des idées, elles sont bienvenues !
Merci
Back to fr.comp.lang.python | Previous | Next — Next in thread | Find similar
Fonction Python et MySQL, pour cr�er une cl� �trang�re Olivier92410 <nospam_olivier.debeyssac@gmail.com.invalid> - 2021-12-03 04:58 -0600 Re: Fonction Python et MySQL, pour créer une clé étrangère Alain Ketterlin <alain@universite-de-strasbourg.fr.invalid> - 2021-12-03 14:57 +0100 Re: Fonction Python et MySQL, pour créer une clé étrangère Nicolas <nicolasp@aaton.com> - 2021-12-06 10:33 +0100
csiph-web