referencing a table which is defined after the definition of the first table in web2py
<pre><code>    db.define_table("devices",
            Field('user_id','reference users'),#   THIS PRODUCES AN ERROR 
            Field('energyConsumed','integer'),
            Field('device_password','password'),
            Field('date_of_measure','date')
            );
db.define_table("users",
            Field('device_id','reference devices')
);
</code></pre>

<p>I am unable to use 'reference users' in the first table because it has not been defined before that tables definition . How can I reference table which is defined only later on .</p>

<p>You can not reference to table which is not defined. So you have to use alternative syntax.</p>

<p>Use <code>IS_IN_DB</code> validator for this.</p>

<pre><code>IS_IN_DB(db, 'users.id')
</code></pre>

<p>This is already answered here:</p>

<p><a href="http://stackoverflow.com/a/38948788/4065350">http://stackoverflow.com/a/38948788/4065350</a>
<a href="https://groups.google.com/forum/#!msg/web2py/yNca8bq0HmM/DmVjCPrODQAJ" rel="nofollow">https://groups.google.com/forum/#!msg/web2py/yNca8bq0HmM/DmVjCPrODQAJ</a></p>

python web2py