Giter Club home page Giter Club logo

Comments (4)

symnatbay avatar symnatbay commented on June 11, 2024

This is the generated query:

('INSERT INTO `dim_Projects` (`Name`, `Id`) VALUES (%s, %s)', ['new project test', 1])

from peewee.

coleifer avatar coleifer commented on June 11, 2024

That doesn't seem right, it shouldn't be inserting anything for the Id column.

Here is an example based on your code, and it shows that the autofield is NOT inserted:

from peewee import *

db = SqliteDatabase(':memory:')

class DimProject(db.Model):
    Id = AutoField()
    Name = CharField()

db.create_tables([DimProject])

import logging
logger = logging.getLogger('peewee')
logger.setLevel(logging.DEBUG)
logger.addHandler(logging.StreamHandler())

DimProject.create(Name='test')

SQL output correctly shows that Peewee is not providing an Id value and letting the db decide.

('INSERT INTO "dimproject" ("Name") VALUES (?)', ['test'])

from peewee.

coleifer avatar coleifer commented on June 11, 2024

The exact same behavior w/MySQL, of course:

from peewee import *

db = MySQLDatabase('peewee_test')

class DimProject(db.Model):
    Id = AutoField()
    Name = CharField()

db.create_tables([DimProject])

import logging
logger = logging.getLogger('peewee')
logger.setLevel(logging.DEBUG)
logger.addHandler(logging.StreamHandler())

DimProject.create(Name='test')
db.drop_tables([DimProject])

Output:

('INSERT INTO `dimproject` (`Name`) VALUES (%s)', ['test'])

from peewee.

symnatbay avatar symnatbay commented on June 11, 2024

Thanks for the quick response. This was a red herring. I obfuscated the model a bit because I don't want to reveal work-related stuff, and in doing so I left out a ForeignKeyField where column_name="Id" instead of "ForeignId". I was mistaken in thinking that the column_name argument was supposed to point this field to the name of the FK field in the other table. Correcting the value solved my problem. I appreciate your time!

from peewee.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.