<?xml version="1.0" encoding="UTF-8"?>    <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
      <channel>
        <title>Index unique column is not being enforced outside of editor.</title>
        <link>https://interactivetools.com/forum/forum-posts.php?Index-unique-column-is-not-being-enforced-outside-of-editor_-83019</link>
        <description></description>
        <pubDate>Sat, 11 Jul 2026 13:05:07 -0700</pubDate>
        <language>en-us</language>
        <atom:link href="https://interactivetools.com/forum/forum-posts.php?rss=1&amp;Index-unique-column-is-not-being-enforced-outside-of-editor_-83019" rel="self" type="application/rss+xml" />

                <item>
          <title>Index unique column is not being enforced outside of editor.</title>
          <link>https://interactivetools.com/forum/forum-posts.php?postNum=2247988#post2247988</link>
          <description><![CDATA[<p>That was slick - it worked like a charm. Wish I had realized that 10 years ago.</p>]]></description>
          <pubDate>Tue, 03 Jun 2025 14:45:19 -0700</pubDate>
          <guid isPermaLink="true">forum-posts.php?postNum=2247988#post2247988</guid>
        </item>
                <item>
          <title>Index unique column is not being enforced outside of editor.</title>
          <link>https://interactivetools.com/forum/forum-posts.php?postNum=2247987#post2247987</link>
          <description><![CDATA[<p>Hi Jeff, </p>
<p>In the field editor "Default Value" is what appears in the field when you create a new record in the CMS.  The user can see this value and change it if needed.</p>
<p>For MySQL, you can set a custom column type at the bottom to something like "INT DEFAULT 555" (without quotes), and if any code attempts to insert a row without specifying a value for that column, it will be set to the specified value (e.g. 555).</p>
<p>Hope that helps!</p>]]></description>
          <pubDate>Tue, 03 Jun 2025 13:28:17 -0700</pubDate>
          <guid isPermaLink="true">forum-posts.php?postNum=2247987#post2247987</guid>
        </item>
                <item>
          <title>Index unique column is not being enforced outside of editor.</title>
          <link>https://interactivetools.com/forum/forum-posts.php?postNum=2247983#post2247983</link>
          <description><![CDATA[<p>Thanks, I can implement that. While on the subject the other think that would be nice is adjusting the default value. When I added a column using quick add, ithe editor creates a medium text field by default with null as the default value. I realized I wanted this as a int with default 0. The column editor changed the data type Ok but ignored the default value leaving it at null. Not a big deal to change it via rhe developer console or any database tool, it would be great if when default value is set, that it was refected in the mysql source. </p>
]]></description>
          <pubDate>Tue, 03 Jun 2025 06:31:16 -0700</pubDate>
          <guid isPermaLink="true">forum-posts.php?postNum=2247983#post2247983</guid>
        </item>
                <item>
          <title>Index unique column is not being enforced outside of editor.</title>
          <link>https://interactivetools.com/forum/forum-posts.php?postNum=2247981#post2247981</link>
          <description><![CDATA[<p>Hi Jeff, </p>
<p>Yea, the CMSB "unique" value validation runs at the application level. </p>
<p>I think we initially did it that way many years ago because virtual hosts didn't always grant INDEX privileges.  You can actually see under: Admin &gt; General &gt; Server Info &gt; Database Server &gt; Privileges we're displaying the INDEX status to indicate if it's available on the server.  That said, it's on our list to implement this feature as well.  </p>
<p>You can either manually add a unique index yourself through the Developer Console plugin, or here's some code you can add to ensure it's always present (such as before an import operation):</p>
<pre class="language-php"><code>// Ensure accounts.username has a UNIQUE INDEX on it
$hasUniqueIndex = DB::query("SHOW INDEX FROM ::accounts WHERE Non_unique = ?", 0)-&gt;pluck('Column_name')-&gt;contains('username');
if (!$hasUniqueIndex) {
    DB::query("ALTER TABLE ::accounts ADD UNIQUE INDEX (username)");
}</code></pre>
<pre><span>You'll then be able to see that index under: CMS Setup &gt; Database &gt; User Accounts] &gt; Source<br />Or: admin.php?menu=database&amp;action=editTable&amp;tableName=accounts#tab_mysqlSource<br /></span></pre>
<blockquote>
<p>ZenDB does not appear to support the REPLACE command, which can be used as an alternative to INSERT. Right now, we need to do a get or query, then insert for each record. </p>
</blockquote>
<p>Try using the DB::query() method as I've done above for executing any custom queries.</p>
<blockquote>
<p><span>Also, would views and stored procedures be possible?</span></p>
</blockquote>
<p>Yes, but we don't have the CMSB logic to store and recreate them in the CMS schema files.  So when we need to do things like that we often add application code to detect and recreate them, or maybe a plugin to do it once, as we often need to move code between servers and need everything to be portable.  I usually use the Developer Console Plugin for quick queries.</p>
<p>Let me know any questions.</p>]]></description>
          <pubDate>Mon, 02 Jun 2025 22:10:57 -0700</pubDate>
          <guid isPermaLink="true">forum-posts.php?postNum=2247981#post2247981</guid>
        </item>
                <item>
          <title>Index unique column is not being enforced outside of editor.</title>
          <link>https://interactivetools.com/forum/forum-posts.php?postNum=2247974#post2247974</link>
          <description><![CDATA[<p>I have a plugin that adds a record to the deliveries_audit_log. I have it checked as unique and indexed. It seems to me that it should make the key unique. It doesn't.</p>
<p>ZenDB does not appear to support the REPLACE command, which can be used as an alternative to INSERT. Right now, we need to do a get or query, then insert for each record. </p>
<p>Also would views and stored procedurs be possible?</p>]]></description>
          <pubDate>Sat, 31 May 2025 20:08:52 -0700</pubDate>
          <guid isPermaLink="true">forum-posts.php?postNum=2247974#post2247974</guid>
        </item>
              </channel>
    </rss>
  