-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror-upgrading-database-with-alembic.html
110 lines (89 loc) · 5.44 KB
/
error-upgrading-database-with-alembic.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<!DOCTYPE html>
<html lang="en">
<head>
<!-- ## for client-side less
<link rel="stylesheet/less" type="text/css" href="http://thierry.ducrest.net/theme/css/style.less">
<script src="http://cdnjs.cloudflare.com/ajax/libs/less.js/1.7.3/less.min.js" type="text/javascript"></script>
-->
<link rel="stylesheet" href="http://thierry.ducrest.net/theme/font-awesome/css/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="http://thierry.ducrest.net/theme/css/style.css">
<link rel="stylesheet" type="text/css" href="http://thierry.ducrest.net/theme/css/pygments.css">
<link rel="stylesheet" type="text/css" href="//fonts.googleapis.com/css?family=PT+Sans|PT+Serif|PT+Mono">
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="author" content="Thierry Ducrest">
<meta name="description" content="Posts and writings by Thierry Ducrest">
<link href="http://feeds.thierry.ducrest.net/feeds/all.atom.xml" type="application/atom+xml" rel="alternate" title=" Atom" />
<meta name="keywords" content="Python, Alembic, Database">
<title>
– Error upgrading database with Alembic </title>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-41998474-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</head>
<body>
<aside>
<div id="user_meta">
<a href="http://thierry.ducrest.net">
<img src="http://thierry.ducrest.net/theme/images/empty.png" alt="logo">
</a>
<h2><a href="http://thierry.ducrest.net">Thierry Ducrest</a></h2>
<p>Software Developer</p>
<ul>
<li><a href="https://github.com/TDu" target="_blank"><i class="fa fa-github fa-lg"></i></a></li>
<li><a href="https://cl.linkedin.com/in/thierry-ducrest-928a394" target="_blank"><i class="fa fa-linkedin-square fa-lg"></i></a></li>
<li><a href="https://twitter.com/thducrest" target="_blank"><i class="fa fa-twitter fa-lg"></i></a></li>
</ul>
</div>
</aside>
<main>
<header>
<p>
<a href="http://thierry.ducrest.net">Index</a> ¦ <a href="http://thierry.ducrest.net/archives.html">Archives</a>
¦ <a href="http://feeds.thierry.ducrest.net/feeds/all.atom.xml">Atom</a>
</p>
</header>
<article>
<h3><a href="http://thierry.ducrest.net/error-upgrading-database-with-alembic.html">Error upgrading database with Alembic</a></h3>
<span class="date-article">12 November 2016</span>
<div class="article_text">
<p>On my last project I started using <a href="https://bitbucket.org/zzzeek/alembic/overview">Alembic</a> as a migration tool for the database, which is a new thing for me.<br>
Before that I used to simply keep a file with the modifications applied to the developement database between each release version and patch the test and production datbase accordingly. Some of the drawbacks to this method are a risk of manipulation error and it is very difficult to reverse the changes when they are applied.</p>
<p>Today while performing an upgrade on the production database running Postgresql with Alembic :</p>
<div class="highlight"><pre><span></span>alembic upgrade head
</pre></div>
<p>I received the following error :</p>
<div class="highlight"><pre><span></span>...
ERROR <span class="o">[</span>alembic.util.messaging<span class="o">]</span> Online migration expected to match one row
when updating <span class="s1">'7b4f4b275d5b'</span> to <span class="s1">'cca4e32787e4'</span> in <span class="s1">'alembic_version'</span><span class="p">;</span> <span class="m">2</span> found
...
</pre></div>
<p>Each database that Alembic work with has an "alembic_version" table, with one column, which contains the id of the current version of the database.</p>
<p>In my database there was two rows in the table alembic_version both with the same value. As the table has no other column to differentiate the rows it is a little bit tricky to remove only one but this did the trick :</p>
<div class="highlight"><pre><span></span><span class="k">DELETE</span> <span class="k">FROM</span> <span class="n">alembic_version</span>
<span class="k">WHERE</span> <span class="n">ctid</span> <span class="k">IN</span> <span class="p">(</span><span class="k">select</span> <span class="n">ctid</span> <span class="k">from</span> <span class="n">alembic_version</span> <span class="k">LIMIT</span> <span class="mi">1</span><span class="p">);</span>
</pre></div>
<p>I do not know why there was two entries in the table but removing one fixed the problem.</p>
</div>
<div class="article_meta">
<p>Posted on: Sat 12 November 2016</p>
<p>Category: <a href="http://thierry.ducrest.net/category/it.html">IT</a>
– Tags:
<a href="http://thierry.ducrest.net/tag/python.html">Python</a>, <a href="http://thierry.ducrest.net/tag/alembic.html">Alembic</a>, <a href="http://thierry.ducrest.net/tag/database.html">Database</a> </p>
</div>
</article>
<div id="ending_message">
<!--
<p>© Thierry Ducrest. Built using <a href="http://getpelican.com" target="_blank">Pelican</a>.</p>
-->
</div>
</main>
</body>
</html>