-1

GitHub URL I’m facing issues with three functions in my Betsy electronics project. Possible causes:

  • Indentation errors.
  • Missing imports.
  • Syntax error.

File structure:

├── README.md
├── betsy.db
├── license.txt
├── main.py
├── models.py
└── test_data.py

Following functions are not populating the SQLite database and I’m unable to determine the cause:

  • ProductTag
  • User
  • UserProduct

I receive the following output:

Product 1 created: True
Product 2 created: True
Product 3 created: True
Product 4 created: True

Tag Electronics updated: True
Tag Apple updated: True
Tag Headphones updated: True
Tag Laptops updated: True

Test database created and populated successfully.

betsy.db

Test database created and populated successfully.

betsy.db

I ran tool for error handling:

- File: 'main.py'
see screenshot 1

- File: 'models.py'
see  screenshot 2

When running the program I receive following output:

The creation of products ('Product 1', 'Product 2', 'Product 3', and 'Product 4') appears to be successful.

The update of tags ('Electronics', 'Apple', 'Headphones', and 'Laptops') in the database also show successful.
user4157124
  • 2,809
  • 13
  • 27
  • 42
  • 1
    Welcome to stackoverflow. Your question is quite verbose, and frankly, I don t know what you are asking or what the problem is. Too much unimportant detail. You mention an error, but I don't see any error message. Please check [ask], then [edit] your question and include a [mcve]. What happens when you run which code and what did you expect to happen instead? Any errors? – Robert Jul 01 '23 at 19:58
  • Thank you for your feedback. Let me clarify. I've created a function with python: def create_product_tag(tag_name, product_name, created_at, updated_at, is_active, description): In my SQLite database i see this function and table's: id = product_tag.id tag_id = product_tag.tag.id product_id = product_tag.product.id created_at = product_tag.created_at updated_at = product_tag.updated_at is_active = product_tag.is_active description = product_tag.description The expected outcome is the database to populated correctly. – Virtual Silvr Jul 09 '23 at 22:51

1 Answers1

0

Couple suggestions:

  • Use database.bind([...]) instead of ModelClass._meta.database = x.
  • Use a full path instead of a relative path for your database
  • Share the SQL being logged

Lastly you never really even explained what the actual issue is, although I have to assume somehow you are not observing the writes to the database.

coleifer
  • 24,887
  • 6
  • 60
  • 75
  • Thank you for your valuable feedback and suggestions. Using database.bind([...]) instead of directly assigning ModelClass._meta.database = x: I will consider this approach for improved code organization and maintainability. I understand the potential path-related issues and will ensure to use a full path for better stability and portability. I am currently using logging. Is this the recommended way to share the SQL statements being logged during database operations? If there are any alternative methods or best practices for accomplishing this, please let me know. – Virtual Silvr Jul 09 '23 at 23:06
  • I've created a Python function named create_product_tag to address my issue. def create_product_tag(tag_name, product_name, created_at, updated_at, is_active, description): In my SQLite database, I observe the following function and corresponding table attributes: python Copy code id = product_tag.id tag_id = product_tag.tag.id product_id = product_tag.product.id created_at = product_tag.created_at updated_at = product_tag.updated_at is_active = product_tag.is_active description = product_tag.description Expected outcome is to have the database populated correctly. – Virtual Silvr Jul 09 '23 at 23:09