我有两个模型:用户和组。
用户可以在一个组中,因此:
class User(db.Model):
# other fields
group_id = db.Column(db.Integer(), db.ForeignKey('group.id'))
Run Code Online (Sandbox Code Playgroud)
但另一方面,我也会有一些有关创建该特定组的用户的信息:
class Group(db.Model):
# other fields
users = db.relationship("User", backref='group')
created_by = db.Column(db.Integer(), db.ForeignKey('user.id'))
Run Code Online (Sandbox Code Playgroud)
结果是:
sqlalchemy.exc.CircularDependencyError: Can't sort tables for DROP; an unresolvable foreign key dependency exists between tables: group, user. Please ensure that the ForeignKey and ForeignKeyConstraint objects involved in the cycle have names so that they can be dropped using DROP CONSTRAINT.
Run Code Online (Sandbox Code Playgroud)
我试过了use_alter=True,但它给了我:
sqlalchemy.exc.CompileError: Can't emit DROP CONSTRAINT for constraint ForeignKeyConstraint(
Run Code Online (Sandbox Code Playgroud) 我想计算当前时间和字符串时间之间的差异(以分钟为单位)。
我有这样的字符串(来自 SQlite 数据库):
String time1= "22:50";
Run Code Online (Sandbox Code Playgroud)
我得到的当前日期为:
Date currentDate = new Date()
long test = currentData.getTime();
Run Code Online (Sandbox Code Playgroud)
解析迄今为止的字符串:
SimpleDateFormat dateFormat = new SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss");
oldDate = dateFormat.parse(time1);
Run Code Online (Sandbox Code Playgroud)
然后区别:
diff = test - oldDate.getTime();
long seconds = diff / 1000;
long minutes = seconds / 60;
Run Code Online (Sandbox Code Playgroud)
但主要问题是由于缺乏当前数据信息引起的(我只有时间)。我想要:来自字符串的当前数据+时间,然后将其与当前日期和时间进行比较。