我想不出如何添加表之间的关系。
class MyModel(BaseModel):
a = peewee.TextField()
b = peewee.TextField()
c = peewee.IntegerField()
d = peewee.TextField()
e = peewee.FloatField()
f = peewee.FloatField()
class Meta:
primary_key = peewee.CompositeKey('a', 'b', 'c
我尝试使用以下命令安装python的peewee模块
sudo pip install peewee,但是当我运行我的脚本时,我仍然得到错误
sudo pip install peewee
[sudo] password for mounarajan:
The directory '/home/mounarajan/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissi
我已经创建了模型类inherititng表单peewee.Model。
import peewee
class Example(peewee.Model):
id = peewee.IntField(primary_key=True)
text = peewee.charField(default="waiting")
dt = peewee.DateTimeField(default=datetime.datetime.now().strftime('%Y-%m-%d'))
但是,当我仅将id字段的新值插入到example表中时,就不
在搜索python示例代码时,我遇到了一个示例:
import peewee
from peewee import *
db = MySQLDatabase('jonhydb', user='john',passwd='megajonhy')
class Book(peewee.Model):
author = peewee.CharField()
title = peewee.TextField()
class Meta:
database = db
我可以理解title = peewee.Text
我遇到了一个关于连接的非常简单的peewee-async问题,或者我可能需要使用子查询,或者预取……我不知道我需要做什么样的查询。
我有两个数据库表(父/子):
class Group(PeeweeModel):
id = peewee.AutoField()
name = peewee.TextField()
class Channel(PeeweeModel):
id = peewee.AutoField()
name = peewee.TextField()
group = peewee.ForeignKeyField(Group, bac
我正在尝试使用peewee和peewee-mssql连接到Microsoft SQL数据库。我已经安装了peewee版本3.10和peewee-mssql版本0.1.3。我试着用Python3.5和Python3.7运行它,结果是一样的。 当我运行这个脚本时: import peewee as pw
from peewee_mssql import MssqlDatabase
db = MssqlDatabase('DATABASE INFO')
db.connect()
tables = db.get_tables()
for t in tables:
pr
这更像是一个一般性的问题,但我正在尝试使用Python在Peewee之上将其实现为ORM。从python程序中抽象出DB的一个好的OO方法是什么?
在Peewee中,定义继承自peewee.Model的类,并将Peewee字段作为attributes.For示例:
class Person(peewee.Model):
class Meta:
database = db
name = peewee.TextField()
height = peewee.DecimalField()
在面向对象的实现中,我们希望有像grow(size),die(),..
使用peewee async时,尝试更新对象时出错:
Traceback (most recent call last):
File "./src/models/module.py", line 74, in run
await self._stage_alert_attach(target_alert)
File "./src/models/module.py", line 293, in _stage_alert_attach
await target_alert.attach(unattached_issues)
File
当我插入一行时,该字段填充的是服务器启动的时间,而不是插入行的时间。为什么会发生这种情况?解决方案是什么?顺便说一句,我使用的是SQLite。
class LOG(peewee.Model):
id = peewee.IntegerField(unique=True,primary_key=True)
timestamp = peewee.DateTimeField(default=datetime.datetime.now())
log = peewee.CharField()
by = peewee.IntegerField(default=1)
c
我正试图在我的项目中实现peewee ORM,但我有一个奇怪的问题:
class Server(peewee.Model):
name = peewee.CharField
class Meta:
database = db
print Server.select().where(Server.name == 'postfix').sql()
返回:
('SELECT `t1`.`id` FROM `server` AS t1 WHERE %s', [False])
运行python2.7.6 w/ peewee 2.6.4
考虑到下面由peewee支持的python代码,如何根据另一个表中跨行的值筛选表中的数据
例如,如果我想在便笺表中得到一个注释,所有的java、lambda、generics标记都在customtags中
#!/usr/bin/env python3
import peewee
import datetime
db = peewee.SqliteDatabase('test.db')
class Note(peewee.Model):
id = peewee.AutoField()
name = peewee.CharField()
text =
我正在尝试使用peewee的迁移模块将列从name重命名为title,在我的page表中。然而,我正在运行这个令人困惑的错误:
peewee.OperationalError: table page__tmp__ has no column named FOREIGN
我的猜测是,它与创建中间表的需要有关,当使用sqlite时。
电流模型:
完整的源代码在这里
class User(BaseModel):
id = peewee.CharField(primary_key=True, max_length=20)
class Page(BaseModel):
id = pe
我见过peewee的an example,其中使用pysqlcipher作为管理数据库文件的连接器,而不是sqlite模块。这很棒,甚至还有一个async version of peewee,但我不需要(或不想)使用peewee的对象模型。在peewee中,连接器是这样初始化的: from peewee import *
from playhouse.sqlcipher_ext import SqlCipherDatabase
db = SqlCipherDatabase(None)
class Entry(Model):
class Meta:
databas
这是可行的:
class MyModel(peewee.Model):
my_field = peewee.IntegerField(null=False, default=0)
class Meta(object):
database = db
db_table = 'MyTable'
这不起作用:
class MyModel(peewee.Model):
class Meta(object):
database = db
db_table = 'MyTable'
s
我和Peewee一起使用Python2.7。此时,我需要使用Peewee执行以下SQL查询:
select
a,
b,
substring(c, 1, 3) as alias1,
count(substring(c, 1, 3)) as alias2
from Table
where <some where condition, not relevant here>
group by a, alias1
这里我的第一个问题是如何使用Peewee执行子字符串。我已经查过文件了,到目前为止,还没有幸运。
因此,基本问题是:如何使用Peewee执行su
我在一个带有MySQL DB的小Python脚本中使用Peewee作为ORM。
#!/usr/bin/python3
#coding: utf-8
import peewee
from peewee import *
db = MySQLDatabase(**config)
class Foo(peewee.Model):
bar = peewee.CharField(unique=True, null=False)
class Meta:
database = db
try:
Foo.create_table()
except:
pass