Files
django-core-base/init_db.py
2026-04-11 13:00:25 +02:00

32 lines
1014 B
Python

import os
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'core.settings')
import django
django.setup()
from django.db import connection
with connection.cursor() as cursor:
cursor.execute("""
CREATE TABLE IF NOT EXISTS promociones (
id INTEGER PRIMARY KEY AUTOINCREMENT,
nombre VARCHAR(255),
fecha_inicio DATE,
descripcion TEXT,
activo BOOLEAN DEFAULT 1,
categoria_id INTEGER
)
""")
cursor.execute("""
INSERT OR IGNORE INTO promociones (id, nombre, fecha_inicio, descripcion, activo, categoria_id)
VALUES (1, 'Promo Test', '2026-04-11', 'Descripcion de prueba', 1, 1)
""")
cursor.execute("""
CREATE TABLE IF NOT EXISTS categorias (
id INTEGER PRIMARY KEY AUTOINCREMENT,
nombre VARCHAR(255)
)
""")
cursor.execute("""
INSERT OR IGNORE INTO categorias (id, nombre)
VALUES (1, 'Categoria Test')
""")
connection.commit()
print('Tablas y datos de prueba creados exitosamente en db.sqlite3')