带有CORS转储数据的Django 1.9:“corsheaders_corsmodel”不存在

时间:2015-12-18 05:05:30

标签: django postgresql django-migrations django-1.9

我正在使用跨站点引用开发Django(1.9)Rest后端和AngularJS前端。尝试执行./manage.py dumpdata命令时,会抛出以下异常:

$ python manage.py dumpdata -o dev/dumpdata.json
CommandError: Unable to serialize database: relation 
"corsheaders_corsmodel" does not exist
LINE 1: SELECT COUNT(*) AS "__count" FROM "corsheaders_corsmodel"

知道如何处理?

2 个答案:

答案 0 :(得分:24)

我遇到了同样的问题,并通过专门针对import numpy as np import tensorflow as tf def main(): x_input = tf.placeholder(tf.float32, shape=(None, 1)) y_output = tf.placeholder(tf.float32, shape=(None, 1)) hidden_weights = tf.Variable(tf.truncated_normal([1,10], stddev=0.1), name='weights') output_weights = tf.Variable(tf.truncated_normal([10,1], stddev=0.1), name='output') inference = tf.matmul(tf.matmul(x_input, hidden_weights), output_weights) regA = tf.reduce_sum(tf.pow(hidden_weights, 2)) regB = tf.reduce_sum(tf.pow(output_weights, 2)) modelError = tf.reduce_mean(tf.pow(tf.sub(inference,y_output),2), name='model-error') fail = True if fail: regularizationTerm = tf.Variable(tf.zeros([1], dtype=np.float32), name='regterm') regularizationTerm += tf.mul(2.0, regA) regularizationTerm += tf.mul(3.0, regB) else: regularizationTerm = tf.add(tf.mul(2.0, regA), tf.mul(3.0, regB), name='regterm') loss = tf.add(modelError, regularizationTerm, name='loss') tf.scalar_summary(loss.op.name, loss) optimizer = tf.train.GradientDescentOptimizer(0.05) global_step = tf.Variable(0, name='global_step', trainable=False) train_op = optimizer.minimize(loss, global_step=global_step) summary_op = tf.merge_all_summaries() saver = tf.train.Saver() sess = tf.Session() init = tf.initialize_all_variables() sess.run(init) summary_writer = tf.train.SummaryWriter('train_dir', graph_def=sess.graph_def) feed_dict = {x_input:np.ones((30,1), dtype=np.float32), y_output:np.ones((30,1), dtype=np.float32)} for step in xrange(1000): _, loss_value = sess.run([train_op, loss], feed_dict=feed_dict) if step % 100 == 0: print( "step=%d loss=%.2f" % (step, loss_value)) summary_str = sess.run(summary_op, feed_dict=feed_dict) summary_writer.add_summary(summary_str, step) if __name__ == '__main__': main() 应用调用python manage.py makemigrations解决了这个问题:

corsheaders

我认为在我的案例中发生的事情是,在从Django 1.8升级到1.9之后,当我更新我的数据库时,从未应用过初始迁移。

我通过注意到$ python manage.py makemigrations corsheaders $ python manage.py migrate 应用未列在corsheaders的{​​{1}}输出中来跟踪它:

Apply all migrations

然而,为python manage.py migrate运行手动迁移实际上会创建初始迁移:

$ python manage.py migrate
Operations to perform:
  Apply all migrations: sessions, admin, xyz, auth, contenttypes
Running migrations:
  No migrations to apply.

完成此操作后,corsheaders会在输出中显示$ python manage.py makemigrations corsheaders Migrations for 'corsheaders': 0001_initial.py: - Create model CorsModel ,并按预期成功应用迁移:

migrate

答案 1 :(得分:2)

如果corsheaders_corsmodel表不存在,那么就没有要转储的数据。 所以你可以运行:

$python manage.py dumpdata --exclude=corsheaders 

我遇到了同样的问题,我就这样解决了。